mirror of https://github.com/tycrek/ass
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.
53 lines
1.9 KiB
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('#uploads-dir') as SlInput,
|
|
idTypeInput: document.querySelector('#uploads-idtype') as SlInput,
|
|
idSizeInput: document.querySelector('#uploads-idsize') as SlInput,
|
|
gfySizeInput: document.querySelector('#uploads-gfysize') as SlInput,
|
|
fileSizeInput: document.querySelector('#uploads-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,
|
|
};
|
|
|
|
// * Setup button click handler
|
|
Elements.submitButton.addEventListener('click', async () => {
|
|
|
|
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),
|
|
};
|
|
|
|
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);
|
|
else alert('good?');
|
|
})
|
|
.catch((err) => errAlert('POST to /setup failed!', err));
|
|
});
|
|
});
|