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';
|
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">
|
<SiteLayout title="Edit Content">
|
||||||
@ -47,7 +41,7 @@ const adminPass = import.meta.env.ADMIN_PASSWORD;
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script define:vars={{ adminUser, adminPass }}>
|
<script>
|
||||||
// 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');
|
||||||
@ -72,11 +66,7 @@ const adminPass = import.meta.env.ADMIN_PASSWORD;
|
|||||||
filenameInput.value = fileParam;
|
filenameInput.value = fileParam;
|
||||||
filenameInput.readOnly = true; // Don't allow changing filename if editing
|
filenameInput.readOnly = true; // Don't allow changing filename if editing
|
||||||
|
|
||||||
const response = await fetch(getApiUrl(`content/${fileParam}`), {
|
const response = await fetch(getApiUrl(`content/${fileParam}`));
|
||||||
headers: {
|
|
||||||
'Authorization': 'Basic ' + btoa(`${adminUser}:${adminPass}`)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) throw new Error('Failed to load content');
|
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, {
|
const response = await fetch(url, {
|
||||||
method: isNewFile ? 'POST' : 'PUT',
|
method: isNewFile ? 'POST' : 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json'
|
||||||
'Authorization': 'Basic ' + btoa(`${adminUser}:${adminPass}`)
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ filename, content })
|
body: JSON.stringify({ filename, content })
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user