Refactor DAV handling and remove unused code
This commit is contained in:
parent
4788813c39
commit
f81cee4647
24
src/index.ts
24
src/index.ts
@ -49,9 +49,6 @@ async function* listAll(bucket: R2Bucket, prefix: string, isRecursive: boolean =
|
|||||||
} while (r2_objects.truncated);
|
} while (r2_objects.truncated);
|
||||||
}
|
}
|
||||||
|
|
||||||
const DAV_CLASS = '1';
|
|
||||||
const SUPPORT_METHODS = ['OPTIONS', 'PROPFIND', 'MKCOL', 'GET', 'HEAD', 'PUT', 'COPY', 'MOVE'];
|
|
||||||
|
|
||||||
type DavProperties = {
|
type DavProperties = {
|
||||||
creationdate: string | undefined;
|
creationdate: string | undefined;
|
||||||
displayname: string | undefined;
|
displayname: string | undefined;
|
||||||
@ -95,16 +92,6 @@ function make_resource_path(request: Request): string {
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handle_options(request: Request, bucket: R2Bucket): Promise<Response> {
|
|
||||||
return new Response(null, {
|
|
||||||
status: 204,
|
|
||||||
headers: {
|
|
||||||
DAV: DAV_CLASS,
|
|
||||||
Allow: SUPPORT_METHODS.join(', '),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handle_head(request: Request, bucket: R2Bucket): Promise<Response> {
|
async function handle_head(request: Request, bucket: R2Bucket): Promise<Response> {
|
||||||
let response = await handle_get(request, bucket);
|
let response = await handle_get(request, bucket);
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
@ -570,10 +557,19 @@ async function handle_move(request: Request, bucket: R2Bucket): Promise<Response
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DAV_CLASS = '1';
|
||||||
|
const SUPPORT_METHODS = ['OPTIONS', 'PROPFIND', 'MKCOL', 'GET', 'HEAD', 'PUT', 'COPY', 'MOVE'];
|
||||||
|
|
||||||
async function dispatch_handler(request: Request, bucket: R2Bucket): Promise<Response> {
|
async function dispatch_handler(request: Request, bucket: R2Bucket): Promise<Response> {
|
||||||
switch (request.method) {
|
switch (request.method) {
|
||||||
case 'OPTIONS': {
|
case 'OPTIONS': {
|
||||||
return await handle_options(request, bucket);
|
return new Response(null, {
|
||||||
|
status: 204,
|
||||||
|
headers: {
|
||||||
|
Allow: SUPPORT_METHODS.join(', '),
|
||||||
|
DAV: DAV_CLASS,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
case 'HEAD': {
|
case 'HEAD': {
|
||||||
return await handle_head(request, bucket);
|
return await handle_head(request, bucket);
|
||||||
|
Loading…
Reference in New Issue
Block a user