feat: add admin edit page with content preview and save functionality
This commit is contained in:
parent
df15dc91db
commit
2576a5cd41
@ -1,7 +1,11 @@
|
|||||||
---
|
---
|
||||||
import SiteLayout from '../../components/SiteLayout.astro';
|
import SiteLayout from '../../components/SiteLayout.astro';
|
||||||
|
|
||||||
// In a real app, you'd check authentication here
|
// Ensure ADMIN_USERNAME and ADMIN_PASSWORD env vars are set in Coolify
|
||||||
|
// and match the credentials Caddy uses for Basic Auth.
|
||||||
|
// From Caddy logs, username should be 'Gregman'.
|
||||||
|
const adminUser = import.meta.env.ADMIN_USERNAME;
|
||||||
|
const adminPass = import.meta.env.ADMIN_PASSWORD;
|
||||||
---
|
---
|
||||||
|
|
||||||
<SiteLayout title="Edit Content">
|
<SiteLayout title="Edit Content">
|
||||||
@ -43,7 +47,7 @@ import SiteLayout from '../../components/SiteLayout.astro';
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script define:vars={{ adminUser, adminPass }}>
|
||||||
// Get query params
|
// Get query params
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const fileParam = urlParams.get('file');
|
const fileParam = urlParams.get('file');
|
||||||
@ -70,7 +74,7 @@ import SiteLayout from '../../components/SiteLayout.astro';
|
|||||||
|
|
||||||
const response = await fetch(getApiUrl(`content/${fileParam}`), {
|
const response = await fetch(getApiUrl(`content/${fileParam}`), {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Basic ' + btoa('admin:password') // In production, use proper auth
|
'Authorization': 'Basic ' + btoa(`${adminUser}:${adminPass}`)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -112,7 +116,7 @@ import SiteLayout from '../../components/SiteLayout.astro';
|
|||||||
method: isNewFile ? 'POST' : 'PUT',
|
method: isNewFile ? 'POST' : 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Basic ' + btoa('admin:password') // In production, use proper auth
|
'Authorization': 'Basic ' + btoa(`${adminUser}:${adminPass}`)
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ filename, content })
|
body: JSON.stringify({ filename, content })
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user