You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ass/frontend/setup.mts

53 lines
1.9 KiB

import { SlInput, SlButton } from '@shoelace-style/shoelace';
import { IdType, UserConfiguration } from 'ass';
const genericErrorAlert = () => alert('An error occured, please check the console for details');
const errAlert = (logTitle: string, err: any, stream: 'error' | 'warn' = 'error') => (console[stream](logTitle, err), genericErrorAlert());
// * Wait for the document to be ready
document.addEventListener('DOMContentLoaded', () => {
const Elements = {
dirInput: document.querySelector('#dir') as SlInput,
idTypeInput: document.querySelector('#idtype') as SlInput,
idSizeInput: document.querySelector('#idsize') as SlInput,
gfySizeInput: document.querySelector('#gfysize') as SlInput,
fileSizeInput: document.querySelector('#filesize') as SlInput,
s3endpoint: document.querySelector('#s3-endpoint') as SlInput,
s3bucket: document.querySelector('#s3-bucket') as SlInput,
s3accessKey: document.querySelector('#s3-accessKey') as SlInput,
s3secretKey: document.querySelector('#s3-secretKey') as SlInput,
s3region: document.querySelector('#s3-region') as SlInput,
submitButton: document.querySelector('#submit') as SlButton,
};
1 year ago
// * Setup button click handler
Elements.submitButton.addEventListener('click', async () => {
1 year ago
const config: UserConfiguration = {
uploadsDir: Elements.dirInput.value,
idType: Elements.idTypeInput.value as IdType,
idSize: parseInt(Elements.idSizeInput.value),
gfySize: parseInt(Elements.gfySizeInput.value),
maximumFileSize: parseInt(Elements.fileSizeInput.value),
1 year ago
};
1 year ago
fetch('/setup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(config)
})
.then((res) => res.json())
.then((data: {
success: boolean,
message: string
}) => {
if (!data.success) alert(data.message);
1 year ago
else alert('good?');
})
.catch((err) => errAlert('POST to /setup failed!', err));
});
});