51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
|
import config from '../config.mjs'
|
||
|
import Client from './client.mjs'
|
||
|
|
||
|
export function upload(file) {
|
||
|
const media = config.get('media')
|
||
|
|
||
|
const client = new Client()
|
||
|
let token = client.createJwt({ iss: media.iss }, media.secret)
|
||
|
|
||
|
let out = {
|
||
|
small: {},
|
||
|
medium: {},
|
||
|
large: {},
|
||
|
}
|
||
|
|
||
|
return client.upload(media.path + '?token=' + token, { file: {
|
||
|
file: file.path,
|
||
|
filename: file.name,
|
||
|
} }, 'POST', {
|
||
|
preview: media.preview,
|
||
|
small: media.small.avif,
|
||
|
medium: media.medium.avif,
|
||
|
large: media.large.avif,
|
||
|
/*
|
||
|
|
||
|
small: media.small.jpeg,
|
||
|
medium: media.medium.avif,
|
||
|
large_jpeg: media.large.jpeg,*/
|
||
|
}).then(res => {
|
||
|
out.filename = res.filename
|
||
|
out.path = res.path
|
||
|
out.preview = res.preview
|
||
|
out.small.avif = res.small
|
||
|
out.medium.avif = res.medium
|
||
|
out.large.avif = res.large
|
||
|
|
||
|
return client.post(media.path + '/' + out.filename + '?token=' + token, {
|
||
|
small: media.small.jpeg,
|
||
|
medium: media.medium.jpeg,
|
||
|
large: media.large.jpeg,
|
||
|
})
|
||
|
.then(res => {
|
||
|
out.small.jpeg = res.small
|
||
|
out.medium.jpeg = res.medium
|
||
|
out.large.jpeg = res.large
|
||
|
})
|
||
|
})
|
||
|
.then(() => {
|
||
|
return out
|
||
|
})
|
||
|
}
|