Skip to content

Commit 2ef413d

Browse files
author
Blastradius
committed
refactor: fix lint issues
1 parent 60c112d commit 2ef413d

13 files changed

Lines changed: 71 additions & 54 deletions

File tree

bin/cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22
import * as commander from "commander";
3+
34
import { parseAsync } from "../src/actions/parseAsync.js";
45
import { searchAsync } from "../src/actions/searchAsync.js";
56

src/actions/parseAsync.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import * as javit from "../index.js";
21
import fs from "node:fs";
32
import path from "node:path";
43

4+
import * as javit from "../index.js";
5+
56
/**
67
* @param {string[]} paths
78
* @param {{ force?: boolean }} options
@@ -17,7 +18,7 @@ export async function parseAsync(paths, options) {
1718
* @param {boolean} force
1819
*/
1920
async function checkAsync(path, force) {
20-
const stats = await fs.promises.stat(path).catch(() => undefined);
21+
const stats = await fs.promises.stat(path).catch(() => {});
2122
if (!stats) {
2223
console.log(`Rejected ${path}`);
2324
} else if (stats.isDirectory()) {
@@ -40,16 +41,16 @@ async function directoryAsync(directoryPath, force) {
4041
const childPaths = childNames.map((name) => path.join(directoryPath, name));
4142
const childSet = new Set(childPaths);
4243
for (const childPath of childPaths) {
43-
const stats = await fs.promises.stat(childPath).catch(() => undefined);
44+
const stats = await fs.promises.stat(childPath).catch(() => {});
4445
if (stats?.isDirectory()) {
4546
await checkAsync(childPath, force);
4647
} else if (stats?.isFile() && isVideo(childPath)) {
4748
const { dir, name } = path.parse(childPath);
4849
const fanartPath = path.join(dir, `${name}-fanart.jpg`);
4950
const posterPath = path.join(dir, `${name}.jpg`);
5051
if (force || !childSet.has(fanartPath) || !childSet.has(posterPath)) {
51-
await fs.promises.unlink(fanartPath).catch(() => undefined);
52-
await fs.promises.unlink(posterPath).catch(() => undefined);
52+
await fs.promises.unlink(fanartPath).catch(() => {});
53+
await fs.promises.unlink(posterPath).catch(() => {});
5354
await checkAsync(childPath, force);
5455
}
5556
}

src/functions/getCode.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/** @param {string} name */
2-
export function getCode(name) {
3-
const matches = patterns.map((pattern) => name.match(pattern));
4-
const match = matches.find(Boolean);
5-
return match ? `${match[1]?.toUpperCase()}-${match[2]}` : undefined;
6-
}
7-
81
const patterns = [
92
/([A-Z]{2,})-([0-9]{3,})/,
103
/([a-z]{2,})-([0-9]{3,})/,
114
/([A-Z]{2,})([0-9]{3,})/,
125
/([a-z]{2,})([0-9]{3,})/,
136
];
7+
8+
/** @param {string} name */
9+
export function getCode(name) {
10+
const matches = patterns.map((pattern) => name.match(pattern));
11+
const match = matches.find(Boolean);
12+
return match ? `${match[1]?.toUpperCase()}-${match[2]}` : undefined;
13+
}

src/functions/parseAsync.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import fs from "node:fs";
22
import path from "node:path";
33
import sanitizeFilename from "sanitize-filename";
4+
45
import { getCode } from "./getCode.js";
5-
import { getPosterAsync } from "./utils/getPosterAsync.js";
66
import { searchAsync } from "./searchAsync.js";
7+
import { getPosterAsync } from "./utils/getPosterAsync.js";
78

89
/** @param {string} filePath */
910
export async function parseAsync(filePath) {
@@ -13,8 +14,7 @@ export async function parseAsync(filePath) {
1314
if (metadata) {
1415
const newName = sanitizeFilename(metadata.title).slice(0, 120).trim();
1516
const newPath = path.join(dir, newName + ext);
16-
const didFail = await renameAsync(filePath, newPath);
17-
if (!didFail) {
17+
if (await renameAsync(filePath, newPath)) {
1818
await downloadAsync(dir, metadata.imageUrl, newName);
1919
return "OK";
2020
} else {
@@ -26,16 +26,16 @@ export async function parseAsync(filePath) {
2626
}
2727

2828
/**
29-
* @param {string} dir
29+
* @param {string} directoryPath
3030
* @param {URL} imageUrl
3131
* @param {string} name
3232
*/
33-
async function downloadAsync(dir, imageUrl, name) {
33+
async function downloadAsync(directoryPath, imageUrl, name) {
3434
const response = await fetch(imageUrl);
35-
const fanart = await response.arrayBuffer().then(Buffer.from);
35+
const fanart = await response.arrayBuffer().then(Buffer.from.bind(Buffer));
3636
const poster = await getPosterAsync(fanart);
37-
await fs.promises.writeFile(path.join(dir, `${name}-fanart.jpg`), fanart);
38-
await fs.promises.writeFile(path.join(dir, `${name}.jpg`), poster);
37+
await writeImageAsync(path.join(directoryPath, `${name}-fanart.jpg`), fanart);
38+
await writeImageAsync(path.join(directoryPath, `${name}.jpg`), poster);
3939
}
4040

4141
/**
@@ -49,10 +49,19 @@ async function renameAsync(oldPath, newPath) {
4949
.then(() => true)
5050
.catch(() => false);
5151
if (exists) {
52-
return true;
52+
return false;
5353
} else {
5454
await fs.promises.rename(oldPath, newPath);
5555
}
5656
}
57-
return false;
57+
return true;
58+
}
59+
60+
/**
61+
* @param {string} filePath
62+
* @param {Buffer} buffer
63+
*/
64+
async function writeImageAsync(filePath, buffer) {
65+
await fs.promises.writeFile(`${filePath}.tmp`, buffer);
66+
await fs.promises.rename(`${filePath}.tmp`, filePath);
5867
}

src/functions/providers/7mmtv.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as cheerio from "cheerio";
2-
import { Metadata } from "../Metadata.js";
2+
33
import { getCode } from "../getCode.js";
4+
import { Metadata } from "../Metadata.js";
45
import { normalizeTitle } from "./utils/normalizeTitle.js";
56

67
/** @param {string} code */
@@ -37,7 +38,7 @@ async function searchAsync($, code, url) {
3738
return videoAsync($, new URL(response.url));
3839
}
3940
}
40-
return undefined;
41+
return;
4142
}
4243

4344
/**
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import test from "node:test";
21
import { strictEqual } from "node:assert";
3-
import { try7mmtv } from "./7mmtv.js";
2+
import test from "node:test";
43

5-
test("7mmtv", async () => {
6-
const metadata = await try7mmtv(target.code);
7-
strictEqual(metadata?.imageUrl.pathname, target.imagePath);
8-
strictEqual(metadata?.title, target.title);
9-
});
4+
import { try7mmtv } from "./7mmtv.js";
105

116
const target = {
127
code: "MIRD-163",
138
imagePath: "/censored/b/135637_MIRD-163.jpg",
149
title: "MIRD-163 The Prince And His 10 Eternally Submissive Maids",
1510
};
11+
12+
await test("7mmtv", async () => {
13+
const metadata = await try7mmtv(target.code);
14+
strictEqual(metadata?.imageUrl.pathname, target.imagePath);
15+
strictEqual(metadata?.title, target.title);
16+
});

src/functions/providers/bestjavporn.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as cheerio from "cheerio";
2-
import { Metadata } from "../Metadata.js";
2+
33
import { getCode } from "../getCode.js";
4+
import { Metadata } from "../Metadata.js";
45
import { normalizeTitle } from "./utils/normalizeTitle.js";
56

67
/** @param {string} code */
@@ -34,7 +35,7 @@ async function searchAsync($, code, url) {
3435
return videoAsync($, new URL(response.url));
3536
}
3637
}
37-
return undefined;
38+
return;
3839
}
3940

4041
/**
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import test from "node:test";
21
import { strictEqual } from "node:assert";
3-
import { tryBestJavPorn } from "./bestjavporn.js";
2+
import test from "node:test";
43

5-
test("bestjavporn", async () => {
6-
const metadata = await tryBestJavPorn(target.code);
7-
strictEqual(metadata?.imageUrl.pathname, target.imagePath);
8-
strictEqual(metadata?.title, target.title);
9-
});
4+
import { tryBestJavPorn } from "./bestjavporn.js";
105

116
const target = {
127
code: "MIRD-163",
138
imagePath: "/digital/video/mird00163/mird00163pl.jpg",
149
title: "MIRD-163 The Prince And His 10 Eternally Submissive Maids",
1510
};
11+
12+
await test("bestjavporn", async () => {
13+
const metadata = await tryBestJavPorn(target.code);
14+
strictEqual(metadata?.imageUrl.pathname, target.imagePath);
15+
strictEqual(metadata?.title, target.title);
16+
});

src/functions/providers/javmost.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as cheerio from "cheerio";
2-
import { Metadata } from "../Metadata.js";
2+
33
import { getCode } from "../getCode.js";
4+
import { Metadata } from "../Metadata.js";
45
import { normalizeTitle } from "./utils/normalizeTitle.js";
56

67
/** @param {string} code */
@@ -34,7 +35,7 @@ async function searchAsync($, code, url) {
3435
return videoAsync($, new URL(response.url));
3536
}
3637
}
37-
return undefined;
38+
return;
3839
}
3940

4041
/**
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import test from "node:test";
21
import { strictEqual } from "node:assert";
3-
import { tryJavMost } from "./javmost.js";
2+
import test from "node:test";
43

5-
test("javmost", async () => {
6-
const metadata = await tryJavMost(target.code);
7-
strictEqual(metadata?.imageUrl.pathname, target.imagePath);
8-
strictEqual(metadata?.title, target.title);
9-
});
4+
import { tryJavMost } from "./javmost.js";
105

116
const target = {
127
code: "MIRD-163",
138
imagePath: "/file_image/MIRD-163-UNCENSORED-LEAK.jpg",
149
title: "MIRD-163 King To Live With Endless Obedient Maid 10 People",
1510
};
11+
12+
await test("javmost", async () => {
13+
const metadata = await tryJavMost(target.code);
14+
strictEqual(metadata?.imageUrl.pathname, target.imagePath);
15+
strictEqual(metadata?.title, target.title);
16+
});

0 commit comments

Comments
 (0)