1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
.pragma library
// The file state's Do row. op is a fileops operation, or "md" for the
// daemon's write, or "compress", which opens the COMPRESS formats. kinds
// lists the staged kinds it fits ("any" fits every mix); min is the number
// of files it needs; format is the suffix a file already has when the
// operation would not change it.
const OPS = [
{ label: "To .md", op: "md", kinds: ["pdf"] },
{ label: "To images", op: "pdf-images", kinds: ["pdf"] },
{ label: "Merge", op: "pdf-merge", kinds: ["pdf"], min: 2 },
{ label: "Extract audio", op: "audio", kinds: ["video"] },
{ label: "To MP4", op: "mp4", kinds: ["video"], format: [".mp4"] },
{ label: "To WebM", op: "webm", kinds: ["video"], format: [".webm"] },
{ label: "To GIF", op: "gif", kinds: ["video"] },
{ label: "Trackcrop", op: "trackcrop", kinds: ["video"] },
{ label: "To PNG", op: "png", kinds: ["image"], format: [".png"] },
{ label: "To JPEG", op: "jpeg", kinds: ["image"], format: [".jpg", ".jpeg"] },
{ label: "To WebP", op: "webp", kinds: ["image"], format: [".webp"] },
{ label: "Resize 50%", op: "half", kinds: ["image"] },
{ label: "Extract", op: "extract", kinds: ["archive"] },
{ label: "Compress…", op: "compress", kinds: ["any"] },
];
const COMPRESS = [
{ label: ".zip", op: "zip" },
{ label: ".tar.gz", op: "tgz" },
{ label: ".tar.xz", op: "txz" },
{ label: ".tar.bz2", op: "tbz2" },
];
function ext(name) {
const n = name.toLowerCase(), dot = n.lastIndexOf(".");
return dot > 0 ? n.slice(dot) : "";
}
function offered(files) {
if (!files.length) return [];
return OPS.filter(o => (o.kinds.includes("any") || files.every(f => o.kinds.includes(f.kind)))
&& files.length >= (o.min ?? 1)
&& !(o.format && files.every(f => o.format.includes(ext(f.name)))));
}
|