1
0
Fork 0
upl/web/src/main.js

49 lines
933 B
JavaScript
Raw Normal View History

2021-05-22 13:12:14 +08:00
import Uppy from '@uppy/core';
import DragDrop from '@uppy/drag-drop';
import StatusBar from '@uppy/status-bar';
import AwsS3Multipart from '@uppy/aws-s3-multipart';
/* CSS */
import 'tailwindcss/tailwind.css';
2021-05-22 13:12:14 +08:00
import '@uppy/core/dist/style.css';
import '@uppy/drag-drop/dist/style.css';
import '@uppy/status-bar/dist/style.css';
/* Components */
2021-05-22 13:12:14 +08:00
2021-05-22 22:24:28 +08:00
import Log from './log';
const log = new Log('#log-area', window.location.pathname);
document.querySelector('#log-clear').addEventListener('click', () => {
log.clear();
});
/* Uppy */
2021-05-22 13:12:14 +08:00
const uppy = new Uppy({
autoProceed: true,
});
uppy.use(DragDrop, {
target: '#drop-area',
2021-05-22 22:24:28 +08:00
height: '16rem',
2021-05-22 13:12:14 +08:00
});
uppy.use(StatusBar, {
target: '#status-area',
});
uppy.use(AwsS3Multipart, {
limit: 3,
2021-05-22 23:53:00 +08:00
companionUrl: window.location.pathname,
2021-05-22 13:12:14 +08:00
});
/* Uppy handlers */
2021-05-22 22:24:28 +08:00
2021-05-22 13:12:14 +08:00
uppy.on('upload-success', (f, res) => {
2021-05-22 22:24:28 +08:00
log.add({
name: f.name,
size: f.size,
location: res.body.Location,
});
});