Add new settings

This commit is contained in:
2023-08-06 22:25:01 +08:00
parent 76160ea9ac
commit 04ba13724d
4 changed files with 86 additions and 1 deletions

View File

@@ -4,6 +4,10 @@ import {
get_file_response,
GetFileResponseOptions,
} from "../../../server/get_file_response.ts";
import { get_string } from "../../../server/parse_form.ts";
import pbkdf2Hmac from "pbkdf2-hmac";
import { encode } from "std/encoding/base64.ts";
import { get_host } from "../../../server/utils.ts";
export const handler: Handlers = {
async GET(req, ctx) {
@@ -17,6 +21,39 @@ export const handler: Handlers = {
return new Response("File not found.", { status: 404 });
}
const opts: GetFileResponseOptions = {};
if (m.cfg.img_verify_secret) {
let verify = null;
try {
const form = await req.formData();
verify = await get_string(form.get("verify"));
} catch (_) {
null;
const u = new URL(req.url);
verify = u.searchParams.get("verify");
}
const tverify = encode(
new Uint8Array(
await pbkdf2Hmac(
`id`,
m.cfg.img_verify_secret,
1000,
64,
"SHA-512",
),
),
);
if (verify === null) {
const b = new URLSearchParams();
b.append("verify", tverify);
return Response.redirect(
`${get_host(req)}/api/file/${f.id}?${b}`,
);
}
if (verify !== tverify) {
return new Response("Invalid verify.", { status: 400 });
}
}
opts.cache_control = "public, max-age=31536000";
opts.range = req.headers.get("range");
opts.if_modified_since = req.headers.get("If-Modified-Since");
opts.if_unmodified_since = req.headers.get("If-Unmodified-Since");

View File

@@ -1,7 +1,11 @@
import { Handlers } from "$fresh/server.ts";
import { exists } from "std/fs/exists.ts";
import { get_task_manager } from "../../../server.ts";
import { parse_bool, parse_int } from "../../../server/parse_form.ts";
import {
get_string,
parse_bool,
parse_int,
} from "../../../server/parse_form.ts";
import { generate_filename, ThumbnailConfig } from "../../../thumbnail/base.ts";
import { sure_dir } from "../../../utils.ts";
import { ThumbnailMethod } from "../../../config.ts";
@@ -11,6 +15,8 @@ import {
GetFileResponseOptions,
} from "../../../server/get_file_response.ts";
import { get_host } from "../../../server/utils.ts";
import pbkdf2Hmac from "pbkdf2-hmac";
import { encode } from "std/encoding/base64.ts";
export const handler: Handlers = {
async GET(req, ctx) {
@@ -73,6 +79,39 @@ export const handler: Handlers = {
}
}
const opts: GetFileResponseOptions = {};
if (m.cfg.img_verify_secret) {
let verify = null;
try {
const form = await req.formData();
verify = await get_string(form.get("verify"));
} catch (_) {
null;
const u = new URL(req.url);
verify = u.searchParams.get("verify");
}
const tverify = encode(
new Uint8Array(
await pbkdf2Hmac(
`id`,
m.cfg.img_verify_secret,
1000,
64,
"SHA-512",
),
),
);
if (verify === null) {
const b = new URLSearchParams();
b.append("verify", tverify);
return Response.redirect(
`${get_host(req)}/api/file/${f.id}?${b}`,
);
}
if (verify !== tverify) {
return new Response("Invalid verify.", { status: 400 });
}
}
opts.cache_control = "public, max-age=31536000";
opts.range = req.headers.get("range");
opts.if_modified_since = req.headers.get("If-Modified-Since");
opts.if_unmodified_since = req.headers.get("If-Unmodified-Since");