Added external embeds
This commit is contained in:
parent
5972139552
commit
516a054c31
6 changed files with 70 additions and 16 deletions
|
@ -74,6 +74,9 @@
|
|||
<p>
|
||||
Progress: {progress * 100}%
|
||||
</p>
|
||||
{#if form.success}
|
||||
<p>{form.success}</p>
|
||||
{/if}
|
||||
<p>
|
||||
<Button class="upload-btn" clickFunc={ () => fileInput.click() }>Upload</Button>
|
||||
</p>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<style>
|
||||
img {
|
||||
img, video {
|
||||
max-width: 100px;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
img.only-img {
|
||||
.only-img {
|
||||
max-width: 450px;
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,19 @@
|
|||
{:else}
|
||||
<img src={elem.url} alt='Image preview'>
|
||||
{/if}
|
||||
{:else if elem.type == 'video'}
|
||||
{#if line.filter(x => x.type == 'video').length < 2}
|
||||
<video class='only-img' alt='Video preview' controls>
|
||||
<source src={elem.url}>
|
||||
</video>
|
||||
{:else}
|
||||
<video alt='Video preview' controls>
|
||||
<source src={elem.url}>
|
||||
</video>
|
||||
{/if}
|
||||
{:else if elem.type == 'link'}
|
||||
<a href={elem.url}>{elem.display + ' '}</a>
|
||||
{:else}
|
||||
{:else if !elem.type}
|
||||
{elem + ' '}
|
||||
{/if}
|
||||
{/each}
|
||||
|
|
|
@ -14,7 +14,7 @@ const LEGAL_SORTS = [
|
|||
|
||||
const FILE_SIZE_LIMIT = 1024*1024*16;
|
||||
|
||||
const VALID_EXTENSIONS = ['png','jpg','jpeg','gif','svg']
|
||||
const VALID_EXTENSIONS = ['png','jpg','jpeg','gif','svg', 'mp4'];
|
||||
|
||||
var ridArray = {};
|
||||
|
||||
|
@ -325,13 +325,12 @@ backend.fileCreate = async({img, extension,id, last }) => {
|
|||
const extensionSafe = safePath(extension);
|
||||
|
||||
if (VALID_EXTENSIONS.indexOf(extensionSafe) == -1)
|
||||
return { success: 'Illegal file extension.' };
|
||||
return { success: 'Illegal file extension. Permitted file extensions are: ' + VALID_EXTENSIONS.join(', ') };
|
||||
|
||||
writeFile(`${process.cwd()}/db/post-${imgHash}.${extensionSafe}`,imgData,{encoding: 'base64'});
|
||||
|
||||
return { success: 'Successfully uploaded file.', 'href': `/img/${imgHash}.${extensionSafe}`};
|
||||
}
|
||||
|
||||
export {
|
||||
backendProxy,
|
||||
backend
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
const EXTENSION_MAP = {
|
||||
'png': 'img',
|
||||
'jpg': 'img',
|
||||
'jpeg': 'img',
|
||||
'gif': 'img',
|
||||
'svg': 'img',
|
||||
'mp4': 'video'
|
||||
}
|
||||
|
||||
let checkLength = function(string, field, lowerBound, upperBound) {
|
||||
if (string.length < lowerBound) {
|
||||
if (string.length == 0) {
|
||||
|
@ -74,8 +83,12 @@ let formatPost = function(post) {
|
|||
|
||||
if (cap1 == 'img') {
|
||||
var matchCleaned = safePath(splitPost[1]);
|
||||
splitPost = {'type': 'img', 'url': `/img/${matchCleaned}`};
|
||||
|
||||
var extension = matchCleaned.split('.').pop().toLowerCase();
|
||||
|
||||
extension = safeName(extension);
|
||||
|
||||
splitPost = {'type': EXTENSION_MAP[extension] || 'none', 'url': `/img/${matchCleaned}`};
|
||||
|
||||
return splitPost;
|
||||
}
|
||||
} else if (subPost[0] == '@' || subPost[0] == '#') {
|
||||
|
@ -85,12 +98,28 @@ let formatPost = function(post) {
|
|||
|
||||
splitPost = {'type': 'link', 'display': subPost, 'subtype': type, 'url': `/${type}/${subPostIn}`};
|
||||
|
||||
return splitPost;
|
||||
} else if (subPost.startsWith('https://')) {
|
||||
var url;
|
||||
var extension = subPost.split('.').pop().toLowerCase();
|
||||
|
||||
if (EXTENSION_MAP[extension]) {
|
||||
url = `/embed?url=${encodeURIComponent(subPost)}`;
|
||||
splitPost = [
|
||||
{'type': 'link', 'display': subPost, 'url': url},
|
||||
{'type': EXTENSION_MAP[extension] || 'link', 'display': subPost, 'url': url}
|
||||
];
|
||||
} else {
|
||||
url = subPost;
|
||||
splitPost = {'type': EXTENSION_MAP[extension] || 'link', 'display': subPost, 'url': url};
|
||||
}
|
||||
|
||||
return splitPost;
|
||||
}
|
||||
|
||||
return subPost;
|
||||
})
|
||||
return line;
|
||||
return line.flat();
|
||||
});
|
||||
|
||||
return post;
|
||||
|
|
|
@ -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…
Reference in a new issue