mirror of
https://github.com/System-End/cdn.git
synced 2026-04-19 14:17:05 +00:00
CDN v1 uses Auth passthrough
This commit is contained in:
parent
de82e5b371
commit
85312ea613
2 changed files with 20 additions and 7 deletions
|
|
@ -87,15 +87,22 @@ export default async (req: ServerRequest) => {
|
|||
);
|
||||
}
|
||||
|
||||
const authorization = req.headers.get("Authorization");
|
||||
|
||||
const uploadedURLs = await Promise.all(fileURLs.map(async (url, index) => {
|
||||
const { pathname } = urlParse(url);
|
||||
const filename = index + pathname.substr(pathname.lastIndexOf("/") + 1);
|
||||
|
||||
const res = await (await fetch("https://cdn.hackclub.com/api/newSingle", {
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": ""
|
||||
}
|
||||
if (authorization) {
|
||||
headers['Authorization'] = authorization;
|
||||
}
|
||||
const res = await (await fetch("http://localhost:3000/api/newSingle", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
headers,
|
||||
body: url,
|
||||
})).json();
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,14 @@ const endpoint = (path: string) => {
|
|||
return url;
|
||||
};
|
||||
|
||||
const uploadFile = async (url: string) => {
|
||||
const req = await fetch(url);
|
||||
const uploadFile = async (url: string, authorization: string|null) => {
|
||||
const options = {
|
||||
method: 'GET', headers: { 'Authorization': "" }
|
||||
}
|
||||
if (authorization) {
|
||||
options.headers = { 'Authorization': authorization }
|
||||
}
|
||||
const req = await fetch(url, options);
|
||||
const data = new Uint8Array(await req.arrayBuffer());
|
||||
const sha = new Hash("sha1").digest(data).hex();
|
||||
const size = data.byteLength;
|
||||
|
|
@ -53,7 +59,7 @@ export default async (req: ServerRequest) => {
|
|||
},
|
||||
);
|
||||
}
|
||||
const uploadedFileURL = await uploadFile(singleFileURL);
|
||||
const uploadedFileURL = await uploadFile(singleFileURL, req.headers.get("Authorization"));
|
||||
|
||||
req.respond({
|
||||
body: JSON.stringify(uploadedFileURL),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue