fix (lint): lint and tscheck

This commit is contained in:
MickaelK 2025-08-12 21:03:31 +10:00
parent e397c56544
commit a605988d5c
3 changed files with 22 additions and 14 deletions

View file

@ -1,7 +1,6 @@
import { createElement, createRender, onDestroy } from "../lib/skeleton/index.js";
import rxjs, { effect, onClick } from "../lib/rx.js";
import ajax from "../lib/ajax.js";
import assert from "../lib/assert.js";
import { fromHref, toHref } from "../lib/skeleton/router.js";
import { qs, qsa, safe } from "../lib/dom.js";
import { forwardURLParams } from "../lib/path.js";
@ -291,7 +290,7 @@ async function ctrlTagPane(render) {
}).pipe(
rxjs.map(({ responseJSON }) =>
responseJSON.results
.filter(({type}) => type === "folder")
.filter(({ type }) => type === "folder")
.map(({ name }) => name)
.sort()
),

View file

@ -12,6 +12,18 @@ export default class assert {
return object;
}
/**
* @param {*} object
* @param {string} type
* @param {string} [msg]
* @return {*}
* @throws {TypeError}
*/
static typeof(object, type, msg) {
if (typeof object !== type) throw new TypeError(msg || `assertion failed - unexpected type for ${JSON.stringify(object)}`); // eslint-disable-line valid-typeof
return object;
}
/**
* @param {*} object
* @param {string} [msg]

View file

@ -7,7 +7,6 @@ import assert from "../../lib/assert.js";
import { generateSkeleton } from "../../components/skeleton.js";
import t from "../../locales/index.js";
const shareID = new URLSearchParams(location.search).get("share");
const $tmpl = createElement(`
@ -46,10 +45,10 @@ export default async function(render, { path }) {
}, [])
),
),
ajax({ url: forwardURLParams("api/metadata/search", ["share"]), method: "POST", responseType: "json", body: { path: "/" }}).pipe(
ajax({ url: forwardURLParams("api/metadata/search", ["share"]), method: "POST", responseType: "json", body: { path: "/" } }).pipe(
rxjs.map(({ responseJSON }) =>
responseJSON.results
.filter(({ type, name }) => type === "folder")
.filter(({ type }) => type === "folder")
.map(({ name }) => ({ name, active: false }))
),
),
@ -71,11 +70,9 @@ export default async function(render, { path }) {
const save = (tags) => ajax({
url: forwardURLParams(`api/metadata?path=${path}`, ["share"]),
method: "POST",
body: tags.length === 0 ? [] : [{
id: "tags",
type: "hidden",
value: tags.join(", "),
}],
body: tags.length === 0
? []
: [{ id: "tags", type: "hidden", value: tags.join(", ") }],
}).pipe(rxjs.tap(() => window.dispatchEvent(new Event("filestash::tag"))));
// feature: create DOM
@ -96,7 +93,7 @@ export default async function(render, { path }) {
save(tags$.value
.filter(({ active }) => active)
.map(({ name }) => name)).toPromise();
}
};
return $el;
})),
rxjs.tap(($nodes) => {
@ -111,7 +108,7 @@ export default async function(render, { path }) {
rxjs.filter(() => !shareID),
rxjs.tap((e) => {
e.preventDefault();
const tagname = new FormData(e.target).get("tag").toLowerCase().trim();
const tagname = assert.typeof(new FormData(e.target).get("tag"), "string").toLowerCase().trim();
if (!tagname) return;
else if (tags$.value.find(({ name }) => name === tagname)) return;
qs($modal, `input[name="tag"]`).value = "";