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.
|
|
|
import * as config from './config';
|
|
|
|
import * as math from './math';
|
|
|
|
import * as storage from './storage';
|
|
|
|
|
|
|
|
export async function route(req) {
|
|
|
|
const url = new URL(req.url);
|
|
|
|
|
|
|
|
if (url.pathname === '/api/image') {
|
|
|
|
const desk_id = url.searchParams.get('deskId') || '0';
|
|
|
|
const formData = await req.formData();
|
|
|
|
const file = formData.get('file');
|
|
|
|
const image_id = math.fast_random32();
|
|
|
|
|
|
|
|
await Bun.write(config.IMAGEDIR + '/' + image_id, file);
|
|
|
|
|
|
|
|
storage.put_image(image_id, desk_id);
|
|
|
|
|
|
|
|
return new Response(image_id);
|
|
|
|
} else if (url.pathname === '/api/ping') {
|
|
|
|
return new Response('pong');
|
|
|
|
}
|
|
|
|
}
|