feat: add admin edit page with content preview and save functionality
This commit is contained in:
parent
2576a5cd41
commit
8f41cd5578
@ -1,11 +1,5 @@
|
||||
---
|
||||
import SiteLayout from '../../components/SiteLayout.astro';
|
||||
|
||||
// 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">
|
||||
@ -47,7 +41,7 @@ const adminPass = import.meta.env.ADMIN_PASSWORD;
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script define:vars={{ adminUser, adminPass }}>
|
||||
<script>
|
||||
// Get query params
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const fileParam = urlParams.get('file');
|
||||
@ -72,11 +66,7 @@ const adminPass = import.meta.env.ADMIN_PASSWORD;
|
||||
filenameInput.value = fileParam;
|
||||
filenameInput.readOnly = true; // Don't allow changing filename if editing
|
||||
|
||||
const response = await fetch(getApiUrl(`content/${fileParam}`), {
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + btoa(`${adminUser}:${adminPass}`)
|
||||
}
|
||||
});
|
||||
const response = await fetch(getApiUrl(`content/${fileParam}`));
|
||||
|
||||
if (!response.ok) throw new Error('Failed to load content');
|
||||
|
||||
@ -115,8 +105,7 @@ const adminPass = import.meta.env.ADMIN_PASSWORD;
|
||||
const response = await fetch(url, {
|
||||
method: isNewFile ? 'POST' : 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Basic ' + btoa(`${adminUser}:${adminPass}`)
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ filename, content })
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user