-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathrename.ts
More file actions
154 lines (153 loc) · 4.29 KB
/
Copy pathrename.ts
File metadata and controls
154 lines (153 loc) · 4.29 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import CommonFormats, { Category } from "src/CommonFormats.ts";
import type { FileData, FileFormat, FormatHandler } from "../FormatHandler.ts";
// base class for handling renames
function renameHandler(name: string, formats: FileFormat[]): FormatHandler {
return {
name: name,
ready: true,
supportedFormats: formats,
async init() {
this.ready = true
},
async doConvert(
inputFiles: FileData[],
inputFormat: FileFormat,
outputFormat: FileFormat
): Promise<FileData[]> {
return inputFiles.map(file => {
file.name = file.name.split(".").slice(0, -1).join(".") + "." + outputFormat.extension;
return file;
});
}
};
}
/// handler for renaming various aliased zip files
export const renameZipHandler = renameHandler("renamezip", [
CommonFormats.ZIP.builder("zip").allowTo(),
CommonFormats.DOCX.builder("docx").allowFrom(),
CommonFormats.XLSX.builder("xlsx").allowFrom(),
CommonFormats.PPTX.builder("pptx").allowFrom(),
{
name: "OpenDocument Text",
format: "odt",
extension: "odt",
mime: "application/vnd.oasis.opendocument.text",
from: true,
to: false,
internal: "odt",
category: Category.DOCUMENT,
lossless: true
},
{
name: "OpenDocument Presentation",
format: "odp",
extension: "odp",
mime: "application/vnd.oasis.opendocument.presentation",
from: true,
to: false,
internal: "odp",
category: Category.PRESENTATION,
lossless: true
},
{
name: "OpenDocument Spreadsheet",
format: "ods",
extension: "ods",
mime: "application/vnd.oasis.opendocument.spreadsheet",
from: true,
to: false,
internal: "ods",
category: Category.SPREADSHEET,
lossless: true
},
{
name: "Firefox Plugin",
format: "xpi",
extension: "xpi",
mime: "application/x-xpinstall",
from: true,
to: false,
internal: "xpi",
category: Category.ARCHIVE,
lossless: true
},
CommonFormats.ZIP.builder("love").allowFrom()
.withFormat("love").withExt("love").named("LÖVE Game Package"),
CommonFormats.ZIP.builder("osz").allowFrom()
.withFormat("osz").withExt("osz").named("osu! Beatmap"),
CommonFormats.ZIP.builder("osk").allowFrom()
.withFormat("osk").withExt("osk").named("osu! Skin"),
CommonFormats.ZIP.builder("apworld").allowFrom()
.withFormat("apworld").withExt("apworld").named("Archipelago World"),
{
name: "Java Archive",
format: "jar",
extension: "jar",
mime: "application/x-java-archive",
from: true,
to: false,
internal: "jar",
category: Category.ARCHIVE,
lossless: true
},
{
name: "Android Package Archive",
format: "apk",
extension: "apk",
mime: "application/vnd.android.package-archive",
from: true,
to: false,
internal: "apk",
category: Category.ARCHIVE,
lossless: true
},
CommonFormats.ZIP.builder("sb3").allowFrom()
.withFormat("sb3").withExt("sb3").named("Scratch 3 Project").withMime("application/x.scratch.sb3"),
CommonFormats.ZIP.builder("ipa").allowFrom()
.withFormat("ipa").withExt("ipa").named("iOS Application"),
CommonFormats.ZIP.builder("app").allowFrom()
.withFormat("app").withExt("app").named("macOS Application Bundle"),
{
name: "Comic Book Archive (ZIP)",
format: "cbz",
extension: "cbz",
mime: "application/vnd.comicbook+zip",
from: true,
to: false,
internal: "cbz",
category: Category.ARCHIVE,
lossless: true
},
]);
/// handler for renaming text-based formats
export const renameTxtHandler = renameHandler("renametxt", [
CommonFormats.TEXT.builder("text").allowTo(),
CommonFormats.JSON.builder("json").allowFrom(),
CommonFormats.XML.builder("xml").allowFrom(),
CommonFormats.YML.builder("yaml").allowFrom()
]);
/// handler for renaming json-based formats
export const renameJsonHandler = renameHandler("renamejson", [
CommonFormats.JSON.builder("json").allowTo(),
{
name: "HTTP Archive",
format: "har",
extension: "har",
mime: "application/har+json",
from: true,
to: false,
category: Category.ARCHIVE,
internal: "har"
},
{
name: "Piskel Sprite Save File",
format: "piskel",
extension: "piskel",
mime: "image/png+json",
from: true,
to: false,
category: Category.IMAGE,
internal: "piskel",
lossless: true
}
]);