remove from array

This commit is contained in:
C4illin 2024-05-21 16:27:33 +02:00
parent 74a9252077
commit c8856800a7
6 changed files with 138 additions and 151 deletions

View file

@ -4,7 +4,7 @@ export const Header = ({ loggedIn }: { loggedIn?: boolean }) => {
rightNav = ( rightNav = (
<ul> <ul>
<li> <li>
<a href="/history">History</a> <a href="/test">History</a>
</li> </li>
<li> <li>
<a href="/logout">Logout</a> <a href="/logout">Logout</a>

View file

@ -659,6 +659,7 @@ export async function convert(
// biome-ignore lint/suspicious/noExplicitAny: <explanation> // biome-ignore lint/suspicious/noExplicitAny: <explanation>
options?: any, options?: any,
) { ) {
return exec( return exec(
`ffmpeg -f "${fileType}" -i "${filePath}" -f "${convertTo}" "${targetPath}"`, `ffmpeg -f "${fileType}" -i "${filePath}" -f "${convertTo}" "${targetPath}"`,
(error, stdout, stderr) => { (error, stdout, stderr) => {

View file

@ -16,8 +16,8 @@ import {
const properties: { const properties: {
[key: string]: { [key: string]: {
properties: { properties: {
from: string[] | { [key: string]: string[] }; from: { [key: string]: string[] };
to: string[] | { [key: string]: string[] }; to: { [key: string]: string[] };
options?: { options?: {
[key: string]: { [key: string]: {
[key: string]: { [key: string]: {
@ -36,7 +36,7 @@ const properties: {
targetPath: string, targetPath: string,
// biome-ignore lint/suspicious/noExplicitAny: <explanation> // biome-ignore lint/suspicious/noExplicitAny: <explanation>
options?: any, options?: any,
// biome-ignore lint/suspicious/noExplicitAny: <explanation> // biome-ignore lint/suspicious/noExplicitAny: <explanation>
) => any; ) => any;
}; };
} = { } = {
@ -70,12 +70,13 @@ export async function mainConverter(
// biome-ignore lint/suspicious/noExplicitAny: <explanation> // biome-ignore lint/suspicious/noExplicitAny: <explanation>
let converterFunc: any; let converterFunc: any;
let converterName = converter;
if (converter) { if (converter) {
converterFunc = properties[converter]; converterFunc = properties[converter];
} else { } else {
// Iterate over each converter in properties // Iterate over each converter in properties
for (const converterName in properties) { for (converterName in properties) {
const converterObj = properties[converterName]; const converterObj = properties[converterName];
if (!converterObj) { if (!converterObj) {
@ -84,24 +85,15 @@ export async function mainConverter(
// if converter properties.from is an object loop thorugh the keys otherwise use the array // if converter properties.from is an object loop thorugh the keys otherwise use the array
// for example ffmpeg is an object eg from: {video: ["mp4", "webm"], audio: ["mp3"]} // for example ffmpeg is an object eg from: {video: ["mp4", "webm"], audio: ["mp3"]}
if (Array.isArray(converterObj.properties.from) && Array.isArray(converterObj.properties.to)) {
for (const key in converterObj.properties.from) {
if ( if (
converterObj.properties.from.includes(fileType) && converterObj.properties.from[key].includes(fileType) &&
converterObj.properties.to.includes(convertTo) converterObj.properties.to[key].includes(convertTo)
) { ) {
converterFunc = converterObj.converter; converterFunc = converterObj.converter;
break; break;
} }
} else {
for (const key in converterObj.properties.from) {
if (
converterObj.properties.from[key].includes(fileType) &&
converterObj.properties.to[key].includes(convertTo)
) {
converterFunc = converterObj.converter;
break;
}
}
} }
} }
} }
@ -141,19 +133,13 @@ for (const converterName in properties) {
continue; continue;
} }
if (Array.isArray(converterProperties.from)) { for (const key in converterProperties.from) {
for (const extension of converterProperties.from) { if (!converterProperties.from[key] || !converterProperties.to[key]) {
possibleConversions[extension] = converterProperties.to; continue;
} }
} else {
for (const key in converterProperties.from) {
if (!converterProperties.from[key] || !converterProperties.to[key]) {
continue;
}
for (const extension of converterProperties.from[key]) { for (const extension of converterProperties.from[key]) {
possibleConversions[extension] = converterProperties.to[key]; possibleConversions[extension] = converterProperties.to[key];
}
} }
} }
} }
@ -178,12 +164,8 @@ let allTargets: string[] = [];
for (const converterName in properties) { for (const converterName in properties) {
const converterProperties = properties[converterName].properties; const converterProperties = properties[converterName].properties;
if (Array.isArray(converterProperties.from)) { for (const key in converterProperties.to) {
allTargets = allTargets.concat(converterProperties.to); allTargets = allTargets.concat(converterProperties.to[key]);
} else {
for (const key in converterProperties.to) {
allTargets = allTargets.concat(converterProperties.to[key]);
}
} }
} }

View file

@ -1,118 +1,122 @@
import { exec } from "node:child_process"; import { exec } from "node:child_process";
export const properties = { export const properties = {
from: [ from: {
"textile", text: [
"tikiwiki", "textile",
"tsv", "tikiwiki",
"twiki", "tsv",
"typst", "twiki",
"vimwiki", "typst",
"biblatex", "vimwiki",
"bibtex", "biblatex",
"bits", "bibtex",
"commonmark", "bits",
"commonmark_x", "commonmark",
"creole", "commonmark_x",
"csljson", "creole",
"csv", "csljson",
"djot", "csv",
"docbook", "djot",
"docx", "docbook",
"dokuwiki", "docx",
"endnotexml", "dokuwiki",
"epub", "endnotexml",
"fb2", "epub",
"gfm", "fb2",
"haddock", "gfm",
"html", "haddock",
"ipynb", "html",
"jats", "ipynb",
"jira", "jats",
"json", "jira",
"latex", "json",
"man", "latex",
"markdown", "man",
"markdown_mmd", "markdown",
"markdown_phpextra", "markdown_mmd",
"markdown_strict", "markdown_phpextra",
"mediawiki", "markdown_strict",
"muse", "mediawiki",
"pandoc native", "muse",
"opml", "pandoc native",
"org", "opml",
"ris", "org",
"rst", "ris",
"rtf", "rst",
"t2t", "rtf",
], "t2t",
to: [ ],
"tei", },
"texinfo", to: {
"textile", text: [
"typst", "tei",
"xwiki", "texinfo",
"zimwiki", "textile",
"asciidoc", "typst",
"asciidoc_legacy", "xwiki",
"asciidoctor", "zimwiki",
"beamer", "asciidoc",
"biblatex", "asciidoc_legacy",
"bibtex", "asciidoctor",
"chunkedhtml", "beamer",
"commonmark", "biblatex",
"commonmark_x", "bibtex",
"context", "chunkedhtml",
"csljson", "commonmark",
"djot", "commonmark_x",
"docbook", "context",
"docbook4", "csljson",
"docbook5", "djot",
"docx", "docbook",
"dokuwiki", "docbook4",
"dzslides", "docbook5",
"epub", "docx",
"epub2", "dokuwiki",
"epub3", "dzslides",
"fb2", "epub",
"gfm", "epub2",
"haddock", "epub3",
"html", "fb2",
"html4", "gfm",
"html5", "haddock",
"icml", "html",
"ipynb", "html4",
"jats", "html5",
"jats_archiving", "icml",
"jats_articleauthoring", "ipynb",
"jats_publishing", "jats",
"jira", "jats_archiving",
"json", "jats_articleauthoring",
"latex", "jats_publishing",
"man", "jira",
"markdown", "json",
"markdown_mmd", "latex",
"markdown_phpextra", "man",
"markdown_strict", "markdown",
"markua", "markdown_mmd",
"mediawiki", "markdown_phpextra",
"ms", "markdown_strict",
"muse", "markua",
"pandoc native", "mediawiki",
"odt", "ms",
"opendocument", "muse",
"opml", "pandoc native",
"org", "odt",
"pdf", "opendocument",
"plain", "opml",
"pptx", "org",
"revealjs", "pdf",
"rst", "plain",
"rtf", "pptx",
"s5", "revealjs",
"slideous", "rst",
"slidy", "rtf",
], "s5",
"slideous",
"slidy",
],
},
}; };
export function convert( export function convert(

View file

@ -3,8 +3,8 @@ import type { FormatEnum } from "sharp";
// declare possible conversions // declare possible conversions
export const properties = { export const properties = {
from: ["jpeg", "png", "webp", "gif", "avif", "tiff", "svg"], from: { images: ["jpeg", "png", "webp", "gif", "avif", "tiff", "svg"] },
to: ["jpeg", "png", "webp", "gif", "avif", "tiff"], to: { images: ["jpeg", "png", "webp", "gif", "avif", "tiff"] },
options: { options: {
svg: { svg: {
scale: { scale: {

View file

@ -511,7 +511,7 @@ const app = new Elysia()
} }
db.run( db.run(
"UPDATE jobs SET num_files = ? WHERE id = ?", "UPDATE jobs SET num_files = ?, status = 'pending' WHERE id = ?",
fileNames.length, fileNames.length,
jobId.value, jobId.value,
); );
@ -540,7 +540,7 @@ const app = new Elysia()
}), }),
}, },
) )
.get("/hist", async ({ body, jwt, redirect, cookie: { auth } }) => { .get("/test", async ({ jwt, redirect, cookie: { auth } }) => {
console.log("results page"); console.log("results page");
if (!auth?.value) { if (!auth?.value) {