mirror of
https://github.com/rikkaneko/paste.git
synced 2025-08-06 22:15:34 +01:00
Rename large_upload endpoint path
Signed-off-by: Joe Ma <rikkaneko23@gmail.com>
This commit is contained in:
parent
f90633bce3
commit
c18f08a4cb
6 changed files with 17 additions and 13 deletions
|
@ -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*
|
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.
|
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.
|
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.
|
Generate the presigned URL for upload large paste to the given S3 endpoint `LARGE_DOWNLOAD_ENDPOINT` using HTTP `GET` request.
|
||||||
|
|
||||||
|
|
|
@ -271,7 +271,7 @@ $(function () {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Retrieve presigned URL for upload large paste
|
// 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',
|
method: 'POST',
|
||||||
body: filtered,
|
body: filtered,
|
||||||
});
|
});
|
||||||
|
@ -294,7 +294,7 @@ $(function () {
|
||||||
throw new Error(`Unable to upload paste: ${(await res1.text()) || `${res1.status} ${res1.statusText}`}`);
|
throw new Error(`Unable to upload paste: ${(await res1.text()) || `${res1.status} ${res1.statusText}`}`);
|
||||||
}
|
}
|
||||||
// Finialize the paste
|
// 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',
|
method: 'POST',
|
||||||
});
|
});
|
||||||
if (res2.ok) {
|
if (res2.ok) {
|
||||||
|
|
4
pnpm-workspace.yaml
Normal file
4
pnpm-workspace.yaml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
onlyBuiltDependencies:
|
||||||
|
- esbuild
|
||||||
|
- sharp
|
||||||
|
- workerd
|
|
@ -6,7 +6,7 @@ import { ERequest, Env, PasteIndexEntry } from '../types';
|
||||||
import { gen_id, get_paste_info_obj } from '../utils';
|
import { gen_id, get_paste_info_obj } from '../utils';
|
||||||
import constants from '../constant';
|
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) {
|
export async function get_presign_url(uuid: string, descriptor: PasteIndexEntry) {
|
||||||
// Use cached presigned url if expiration is more than 10 mins
|
// Use cached presigned url if expiration is more than 10 mins
|
10
src/index.ts
10
src/index.ts
|
@ -23,7 +23,7 @@ import { ERequest, Env, PasteIndexEntry } from './types';
|
||||||
import { serve_static } from './proxy';
|
import { serve_static } from './proxy';
|
||||||
import { check_password_rules, get_paste_info, get_basic_auth, gen_id } from './utils';
|
import { check_password_rules, get_paste_info, get_basic_auth, gen_id } from './utils';
|
||||||
import constants, { fetch_constant } from './constant';
|
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
|
// In favour of new cors() in itty-router v5
|
||||||
const { preflight, corsify } = cors({
|
const { preflight, corsify } = cors({
|
||||||
|
@ -38,10 +38,10 @@ const { preflight, corsify } = cors({
|
||||||
|
|
||||||
const router = Router<ERequest, [Env, ExecutionContext]>({
|
const router = Router<ERequest, [Env, ExecutionContext]>({
|
||||||
before: [
|
before: [
|
||||||
preflight,
|
|
||||||
(_, env) => {
|
(_, env) => {
|
||||||
fetch_constant(env);
|
fetch_constant(env);
|
||||||
},
|
},
|
||||||
|
preflight,
|
||||||
],
|
],
|
||||||
catch: error,
|
catch: error,
|
||||||
finally: [corsify],
|
finally: [corsify],
|
||||||
|
@ -264,7 +264,7 @@ router.post('/', async (request, env, ctx) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle large upload (> 25MB)
|
// 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]
|
// Fetch paste by uuid [4-digit UUID]
|
||||||
router.get('/:uuid/:option?', async (request, env, ctx) => {
|
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 cache = caches.default;
|
||||||
const match_etag = headers.get('If-None-Match') || undefined;
|
const match_etag = headers.get('If-None-Match') || undefined;
|
||||||
// Define the Request object as cache key
|
// 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',
|
method: 'GET',
|
||||||
headers: match_etag
|
headers: match_etag
|
||||||
? {
|
? {
|
||||||
|
@ -570,7 +570,7 @@ router.delete('/:uuid', async (request, env, ctx) => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
ctx.waitUntil(env.PASTE_INDEX.delete(uuid));
|
ctx.waitUntil(env.PASTE_INDEX.delete(uuid));
|
||||||
// Invalidate CF cache
|
// 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');
|
return new Response('OK\n');
|
||||||
} else {
|
} else {
|
||||||
return new Response('Unable to process such request.\n', {
|
return new Response('Unable to process such request.\n', {
|
||||||
|
|
|
@ -29,7 +29,7 @@ export const gen_id = customAlphabet(
|
||||||
export function get_paste_info_obj(uuid: string, descriptor: PasteIndexEntry, env: Env) {
|
export function get_paste_info_obj(uuid: string, descriptor: PasteIndexEntry, env: Env) {
|
||||||
const created = new Date(descriptor.last_modified);
|
const created = new Date(descriptor.last_modified);
|
||||||
const expired = new Date(descriptor.expiration ?? descriptor.last_modified + 2419200000);
|
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 = {
|
const paste_info = {
|
||||||
uuid,
|
uuid,
|
||||||
link,
|
link,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue