55 lines
No EOL
1.3 KiB
JavaScript
55 lines
No EOL
1.3 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 = {
|
|
sizes: {
|
|
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.sizes.small.avif = res.small
|
|
out.sizes.medium.avif = res.medium
|
|
out.sizes.large.avif = res.large
|
|
out.size = file.size
|
|
out.type = file.type
|
|
|
|
return client.post(media.path + '/' + out.filename + '?token=' + token, {
|
|
small: media.small.jpeg,
|
|
medium: media.medium.jpeg,
|
|
large: media.large.jpeg,
|
|
})
|
|
.then(res => {
|
|
out.sizes.small.jpeg = res.small
|
|
out.sizes.medium.jpeg = res.medium
|
|
out.sizes.large.jpeg = res.large
|
|
})
|
|
})
|
|
.then(() => {
|
|
return out
|
|
})
|
|
} |