Rename large_upload endpoint path

Signed-off-by: Joe Ma <rikkaneko23@gmail.com>
This commit is contained in:
Joe Ma 2025-07-29 20:12:39 +08:00
parent f90633bce3
commit c18f08a4cb
No known key found for this signature in database
GPG key ID: 7A0ECF5F5EDC587F
6 changed files with 17 additions and 13 deletions

View file

@ -172,7 +172,7 @@ Delete paste by uuid. *If the password is set, this request requires additional
Update paste setting. *If the password is set, this request requires additional `x-pass` header*
### POST /v2/large_upload/create
### POST /api/large_upload/create
Generate the presigned URL for upload large paste to the given S3 endpoint `LARGE_ENDPOINT` using HTTP `PUT` request.
@ -189,11 +189,11 @@ Generate the presigned URL for upload large paste to the given S3 endpoint `LARG
The `file-size` and `file-sha256sum` field is required.
### POST /v2/large_upload/complete/\<uuid\>
### POST /api/large_upload/complete/\<uuid\>
Finialize the paste created from `/v2/large_upload/create`.
Finialize the paste created from `/api/large_upload/create`.
### GET /v2/large_upload/\<uuid\>
### GET /api/large_upload/\<uuid\>
Generate the presigned URL for upload large paste to the given S3 endpoint `LARGE_DOWNLOAD_ENDPOINT` using HTTP `GET` request.

View file

@ -271,7 +271,7 @@ $(function () {
try {
// Retrieve presigned URL for upload large paste
const res = await fetch(`${ENDPOINT}/v2/large_upload/create`, {
const res = await fetch(`${ENDPOINT}/api/large_upload/create`, {
method: 'POST',
body: filtered,
});
@ -294,7 +294,7 @@ $(function () {
throw new Error(`Unable to upload paste: ${(await res1.text()) || `${res1.status} ${res1.statusText}`}`);
}
// Finialize the paste
const res2 = await fetch(`${ENDPOINT}/v2/large_upload/complete/${create_result.uuid}`, {
const res2 = await fetch(`${ENDPOINT}/api/large_upload/complete/${create_result.uuid}`, {
method: 'POST',
});
if (res2.ok) {

4
pnpm-workspace.yaml Normal file
View file

@ -0,0 +1,4 @@
onlyBuiltDependencies:
- esbuild
- sharp
- workerd

View file

@ -6,7 +6,7 @@ import { ERequest, Env, PasteIndexEntry } from '../types';
import { gen_id, get_paste_info_obj } from '../utils';
import constants from '../constant';
export const router = Router<ERequest, [Env, ExecutionContext]>({ base: '/v2/large_upload' });
export const router = Router<ERequest, [Env, ExecutionContext]>({ base: '/api/large_upload' });
export async function get_presign_url(uuid: string, descriptor: PasteIndexEntry) {
// Use cached presigned url if expiration is more than 10 mins

View file

@ -23,7 +23,7 @@ import { ERequest, Env, PasteIndexEntry } from './types';
import { serve_static } from './proxy';
import { check_password_rules, get_paste_info, get_basic_auth, gen_id } from './utils';
import constants, { fetch_constant } from './constant';
import { get_presign_url, router as large_upload } from './v2/large_upload';
import { get_presign_url, router as large_upload } from './api/large_upload';
// In favour of new cors() in itty-router v5
const { preflight, corsify } = cors({
@ -38,10 +38,10 @@ const { preflight, corsify } = cors({
const router = Router<ERequest, [Env, ExecutionContext]>({
before: [
preflight,
(_, env) => {
fetch_constant(env);
},
preflight,
],
catch: error,
finally: [corsify],
@ -264,7 +264,7 @@ router.post('/', async (request, env, ctx) => {
});
// Handle large upload (> 25MB)
router.all('/v2/large_upload/*', large_upload.fetch);
router.all('/api/large_upload/*', large_upload.fetch);
// Fetch paste by uuid [4-digit UUID]
router.get('/:uuid/:option?', async (request, env, ctx) => {
@ -379,7 +379,7 @@ router.get('/:uuid/:option?', async (request, env, ctx) => {
const cache = caches.default;
const match_etag = headers.get('If-None-Match') || undefined;
// Define the Request object as cache key
const req_key = new Request(`https://${env.SERVICE_URL}/${uuid}`, {
const req_key = new Request(`${env.SERVICE_URL}/${uuid}`, {
method: 'GET',
headers: match_etag
? {
@ -570,7 +570,7 @@ router.delete('/:uuid', async (request, env, ctx) => {
if (res.ok) {
ctx.waitUntil(env.PASTE_INDEX.delete(uuid));
// Invalidate CF cache
ctx.waitUntil(cache.delete(new Request(`https://${env.SERVICE_URL}/${uuid}`)));
ctx.waitUntil(cache.delete(new Request(`${env.SERVICE_URL}/${uuid}`)));
return new Response('OK\n');
} else {
return new Response('Unable to process such request.\n', {

View file

@ -29,7 +29,7 @@ export const gen_id = customAlphabet(
export function get_paste_info_obj(uuid: string, descriptor: PasteIndexEntry, env: Env) {
const created = new Date(descriptor.last_modified);
const expired = new Date(descriptor.expiration ?? descriptor.last_modified + 2419200000);
const link = `https://${env.SERVICE_URL}/${uuid}`;
const link = `${env.SERVICE_URL}/${uuid}`;
const paste_info = {
uuid,
link,