add initial img API endpoints
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
import { writeFileSync } from 'fs';
|
||||
import path from 'path'
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import { BEARER_TOKEN } from '$env/static/private'
|
||||
|
24
src/routes/api/img/delete/+server.ts
Normal file
24
src/routes/api/img/delete/+server.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import path from 'path'
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import { BEARER_TOKEN } from '$env/static/private'
|
||||
import { IMAGE_DIR } from '$env/static/private'
|
||||
import { unlink } from 'node:fs';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const POST = (async ({ request }) => {
|
||||
const data = await request.json();
|
||||
if(data.bearer === BEARER_TOKEN){
|
||||
[ "full", "thumb", "placeholder"].forEach((folder) => {
|
||||
unlink(path.join(IMAGE_DIR, folder, data.name + ".webp"), (e) => {
|
||||
if(e) throw error(500, "could not delete: " + folder + "/" + data.name + ".webp")
|
||||
})
|
||||
})
|
||||
return new Response(JSON.stringify({msg: "Deleted image successfully"}),{
|
||||
status: 200,
|
||||
});
|
||||
}
|
||||
else{
|
||||
throw error(403, "Password incorrect")
|
||||
}
|
||||
|
||||
}) satisfies RequestHandler;
|
24
src/routes/api/img/mv/+server.ts
Normal file
24
src/routes/api/img/mv/+server.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import path from 'path'
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import { BEARER_TOKEN } from '$env/static/private'
|
||||
import { IMAGE_DIR } from '$env/static/private'
|
||||
import { rename } from 'node:fs';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const POST = (async ({ request }) => {
|
||||
const data = await request.json();
|
||||
if(data.bearer === BEARER_TOKEN){
|
||||
[ "full", "thumb", "placeholder"].forEach((folder) => {
|
||||
rename(path.join(IMAGE_DIR, folder, data.old_name + ".webp"), path.join(IMAGE_DIR, folder, data.new_name + ".webp"), (e) => {
|
||||
if(e) throw error(500, "could not mv: " + folder + "/" + data.old_name + ".webp")
|
||||
})
|
||||
});
|
||||
return new Response(JSON.stringify({msg: "Deleted image successfully"}),{
|
||||
status: 200,
|
||||
});
|
||||
}
|
||||
else{
|
||||
throw error(403, "Password incorrect")
|
||||
}
|
||||
|
||||
}) satisfies RequestHandler;
|
Reference in New Issue
Block a user