Added external embeds
This commit is contained in:
parent
5972139552
commit
516a054c31
6 changed files with 70 additions and 16 deletions
|
@ -2,29 +2,31 @@ import { backend, backendProxy } from '../../../lib/db/db.js';
|
|||
|
||||
|
||||
/** @type {import('./$types').RequestHandler} */
|
||||
export async function GET({ url, cookies, params }) {
|
||||
export async function GET({ url, cookies, params, fetch }) {
|
||||
const formEntries = url.searchParams;
|
||||
return await handleReq({
|
||||
cookies,
|
||||
params: formEntries,
|
||||
route: params.route
|
||||
route: params.route,
|
||||
fetch
|
||||
});
|
||||
}
|
||||
|
||||
/** @type {import('./$types').RequestHandler} */
|
||||
export async function POST({ cookies, request, params }) {
|
||||
export async function POST({ cookies, request, params, fetch }) {
|
||||
|
||||
const formEntries = (await request.formData()).entries();
|
||||
|
||||
return await handleReq({
|
||||
cookies,
|
||||
params: formEntries,
|
||||
route: params.route
|
||||
route: params.route,
|
||||
fetch
|
||||
});
|
||||
}
|
||||
|
||||
async function handleReq({ cookies, params, route }) {
|
||||
var backendParams = {cookies};
|
||||
async function handleReq({ cookies, params, route, fetch }) {
|
||||
var backendParams = {cookies,fetch};
|
||||
|
||||
for (const [key, value] of params) {
|
||||
backendParams[key] = value + '';
|
||||
|
@ -33,7 +35,7 @@ async function handleReq({ cookies, params, route }) {
|
|||
return await mainApi({backendParams, route: route});
|
||||
}
|
||||
|
||||
async function mainApi({backendParams, route}) {
|
||||
async function mainApi({backendParams, route, fetch}) {
|
||||
if (Object.keys(backend).indexOf(route) == -1) {
|
||||
return new Response(JSON.stringify({success: 'route doesn\'t exist'}));
|
||||
}
|
||||
|
|
11
src/routes/embed/+server.js
Normal file
11
src/routes/embed/+server.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
/** @type {import('./$types').RequestHandler} */
|
||||
export async function GET({ url, fetch }) {
|
||||
const urlParam = url.searchParams.get('url');
|
||||
|
||||
const output = await fetch(urlParam);
|
||||
|
||||
return new Response(await output.blob(), {'headers': {
|
||||
'Content-Type': output.headers.get("Content-Type")
|
||||
}});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue