Skip to content

Commit

Permalink
refactor: lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
xpadev-net committed Nov 22, 2023
1 parent 95fef4b commit 6c77a7b
Show file tree
Hide file tree
Showing 28 changed files with 627 additions and 114 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"simple-import-sort"
"simple-import-sort",
"import"
],
"extends": [
"eslint:recommended",
Expand All @@ -23,6 +24,7 @@
"@next/next/no-img-element": "off",
"no-unused-vars": "off",
"no-control-regex": "off",
"import/no-duplicates": "error",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"@typescript-eslint/explicit-function-return-type": [
Expand Down
1 change: 0 additions & 1 deletion electron/controllerWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const createControllerWindow = (): void => {
controllerWindow.on("close", (e) => {
if (processingQueue?.status === "processing") {
e.preventDefault();
return;
}
});

Expand Down
9 changes: 5 additions & 4 deletions electron/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { SaveDialogOptions } from "electron";
import type { OpenDialogReturnValue } from "electron";
import type { OpenDialogReturnValue, SaveDialogOptions } from "electron";
import { dialog } from "electron";

import type { FfprobeOutput } from "@/@types/ffmpeg";
import type {
ApiResponseMessage,
ApiResponseSelectComment,
ApiResponseSelectMovie,
} from "@/@types/response.controller";
import type { ApiResponseMessage } from "@/@types/response.controller";
import type { SpawnResult } from "@/@types/spawn";

import { sendMessageToController } from "./controllerWindow";
Expand Down Expand Up @@ -85,7 +84,9 @@ const selectMovie = async (): Promise<
"動画ソースが見つかりませんでした\ndialog / selectMovie / empty streams",
};
}
let width, height, duration;
let width: number = 0,
height: number = 0,
duration: number = 0;
for (const stream of metadata.streams) {
if (stream.width) {
width = stream.width;
Expand Down
11 changes: 6 additions & 5 deletions electron/ffmpeg-stream/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { spawn } from "child_process";
import { createReadStream, createWriteStream, unlink } from "fs";
import { tmpdir } from "os";
import { join } from "path";
import type { Readable } from "stream";
import type { Writable } from "stream";
import type { Readable, Writable } from "stream";
import { PassThrough } from "stream";
import { promisify } from "util";

Expand All @@ -36,7 +35,7 @@ function debugStream(stream: Readable | Writable, name: string): void {

function getTmpPath(prefix = "", suffix = ""): string {
const dir = tmpdir();
const id = Math.random().toString(32).substr(2, 10);
const id = Math.random().toString(32).substring(2, 12);
return join(dir, `${prefix}${id}${suffix}`);
}

Expand Down Expand Up @@ -99,7 +98,8 @@ export class Converter {
typeof arg0 == "string" ? [arg0, arg1] : [undefined, arg0];

if (file != null) {
return void this.createInputFromFile(file, opts);
this.createInputFromFile(file, opts);
return;
}
if (opts.buffer) {
delete opts.buffer;
Expand All @@ -116,7 +116,8 @@ export class Converter {
typeof arg0 == "string" ? [arg0, arg1] : [undefined, arg0];

if (file != null) {
return void this.createOutputToFile(file, opts);
this.createOutputToFile(file, opts);
return;
}
if (opts.buffer) {
delete opts.buffer;
Expand Down
21 changes: 11 additions & 10 deletions electron/ffmpeg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AxiosResponse } from "axios";
import type { AxiosProgressEvent, AxiosResponse } from "axios";
import axios from "axios";
import { app } from "electron";
import * as fs from "fs";
Expand Down Expand Up @@ -102,26 +102,27 @@ const downloadFile = async (
path: string,
): Promise<void> => {
const file = fs.createWriteStream(path);
const onDownloadProgress = (status: AxiosProgressEvent): void => {
const progress = status.loaded / (status.total ?? 1);
sendMessageToBinaryDownloader({
type: "downloadProgress",
name: name,
progress: progress,
});
};
return axios({
method: "get",
url,
responseType: "stream",
onDownloadProgress: (status) => {
const progress = status.loaded / (status.total || 1);
sendMessageToBinaryDownloader({
type: "downloadProgress",
name: name,
progress: progress,
});
},
onDownloadProgress,
}).then((res: AxiosResponse<Stream>) => {
return new Promise<void>((resolve, reject) => {
res.data.pipe(file);
let error: Error;
file.on("error", (err) => {
error = err;
file.close();
reject();
reject(err);
});
file.on("close", () => {
if (!error) {
Expand Down
2 changes: 1 addition & 1 deletion electron/ipcManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { store } from "./store";
import { typeGuard } from "./typeGuard";

const registerListener = (): void => {
ipcMain.handle("request", async (IpcMainEvent, args) => {
ipcMain.handle("request", async (_, args) => {
try {
const value = (args as { data: unknown[] }).data[0];
if (typeGuard.renderer.blob(value)) {
Expand Down
13 changes: 0 additions & 13 deletions electron/lib/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@ const convertToEncodedCookie = (cookie: Cookies): string => {
}
return cookieString;
};
const convertToFfmpegCookie = (cookie: Cookies): string[] => {
const cookies = [];
for (const key in cookie) {
const value = cookie[key];
cookies.push(
`${encodeURIComponent(key)}=${encodeURIComponent(
value,
)}; domain=.nicovideo.jp; path=/`,
);
}
return cookies;
};

const parseCookie = (...cookies: string[]): ParsedCookie[] => {
const result: ParsedCookie[] = [];
Expand Down Expand Up @@ -111,7 +99,6 @@ const formatCookies = (

export {
convertToEncodedCookie,
convertToFfmpegCookie,
filterCookies,
formatCookies,
getAvailableProfiles,
Expand Down
4 changes: 2 additions & 2 deletions electron/lib/niconico/dms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ lib/niconico/dms.ts / downloadDMS / invalid accessRights`,
const manifests = Array.from(
manifestRaw.match(
/https:\/\/.+?\.nicovideo\.jp\/.+?\.m3u8(?:\?sh=[a-zA-Z0-9_-]+)?/g,
) || [],
) ?? [],
);
const getManifestUrl = (format: string): string | undefined => {
for (const url of manifests) {
Expand Down Expand Up @@ -276,7 +276,7 @@ const getSegments = (manifest: string): { segments: string[]; key: string } => {
segments: Array.from(
manifest.match(
/https:\/\/.+?\.nicovideo\.jp\/.+?\.cmf[av](?:\?sh=[a-zA-Z0-9_-]+)?/g,
) || [],
) ?? [],
),
key,
};
Expand Down
2 changes: 1 addition & 1 deletion electron/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const processFrame = (data: Uint8Array): void => {
sendProgress();
return myStream
.on("end", () => fulfill())
.on("error", () => reject())
.on("error", (err) => reject(err))
.pipe(inputStream, { end: false });
}).catch((e) => {
console.warn(e);
Expand Down
6 changes: 1 addition & 5 deletions electron/rendererWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ const createRendererWindow = (): void => {
}
};

const closeRendererWindow = (): void => {
rendererWindow.close();
};

const sendMessageToRenderer = (value: ApiResponsesToRenderer): void => {
if (!isOpen) return;
rendererWindow.webContents.send("response", { ...value, target: "renderer" });
};

export { closeRendererWindow, createRendererWindow, sendMessageToRenderer };
export { createRendererWindow, sendMessageToRenderer };
8 changes: 2 additions & 6 deletions electron/typeGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {
ChromiumProfilesJson,
firefoxContainerDefault,
firefoxContainersJson,
firefoxContainerUser,
ParsedCookie,
} from "@/@types/cookies";
import type {
Expand All @@ -26,13 +25,13 @@ import type {
ApiRequestSetSetting,
} from "@/@types/request.controller";
import type {
ApiRequestBlob,
ApiRequestBuffer,
ApiRequestEnd,
ApiRequestFromRenderer,
ApiRequestLoad,
ApiRequestMessage,
} from "@/@types/request.renderer";
import type { ApiRequestMessage } from "@/@types/request.renderer";
import type { ApiRequestBlob } from "@/@types/request.renderer";

const typeGuard = {
controller: {
Expand Down Expand Up @@ -118,9 +117,6 @@ const typeGuard = {
defaultContainer: (i: unknown): i is firefoxContainerDefault =>
typeof i === "object" &&
typeof (i as firefoxContainerDefault).l10nID === "string",
userContainer: (i: unknown): i is firefoxContainerUser =>
typeof i === "object" &&
typeof (i as firefoxContainerUser).name === "string",
},
chromium: {
profiles: (i: unknown): i is ChromiumProfilesJson =>
Expand Down
7 changes: 1 addition & 6 deletions electron/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
function base64ToUint8Array(base64Str: string): Uint8Array {
const raw = Array.from(atob(base64Str));
return Uint8Array.from(raw.map((x) => x.charCodeAt(0)));
}

const sleep = (time: number): Promise<void> => {
return new Promise<void>((resolve) => {
setTimeout(() => {
Expand All @@ -11,4 +6,4 @@ const sleep = (time: number): Promise<void> => {
});
};

export { base64ToUint8Array, sleep };
export { sleep };
27 changes: 12 additions & 15 deletions electron/utils/niconicomments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,23 @@ const identifyCommentFormat = (input: string): CommentFormat | undefined => {
NiconiComments.typeGuard.v1.threads((json as V1Raw)?.data?.threads)
) {
return "rawV1";
} else if (NiconiComments.typeGuard.v1.threads(json)) {
return "v1";
} else if (NiconiComments.typeGuard.legacy.rawApiResponses(json)) {
return "legacy";
} else if (NiconiComments.typeGuard.owner.comments(json)) {
return "owner";
} else if (
NiconiComments.typeGuard.formatted.comments(json) ||
NiconiComments.typeGuard.formatted.legacyComments(json)
) {
return "formatted";
} else {
if (NiconiComments.typeGuard.v1.threads(json)) {
return "v1";
} else if (NiconiComments.typeGuard.legacy.rawApiResponses(json)) {
return "legacy";
} else if (NiconiComments.typeGuard.owner.comments(json)) {
return "owner";
} else if (
NiconiComments.typeGuard.formatted.comments(json) ||
NiconiComments.typeGuard.formatted.legacyComments(json)
) {
return "formatted";
} else {
return;
}
return;
}
} else if (input.match(/\.txt$/)) {
return "legacyOwner";
}
return;
};

export { identifyCommentFormat };
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"electron-builder": "^24.6.4",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
Expand Down
2 changes: 0 additions & 2 deletions src/@types/cookies.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export type ChromiumBrowser =
| "edge"
| "opera"
| "vivaldi";
export type Browser = ChromiumBrowser | "firefox" | "safari";
export type Platform = "win32" | "darwin";

export type FirefoxProfile = FirefoxBasicProfile | FirefoxContainer;

Expand Down
4 changes: 2 additions & 2 deletions src/components/CommentOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import type { ChangeEvent, FC } from "react";
import { useEffect, useState } from "react";

import type {
TCommentOption,
TCommentOptionEndPoint,
TCommentPickerMode,
TCommentThread,
V3MetadataComment,
} from "@/@types/niconico";
import type { TCommentOption } from "@/@types/niconico";
import type { TCommentPickerMode } from "@/@types/niconico";
import { formatDate } from "@/util/time";

import Styles from "./CommentOption.module.scss";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { FormControlLabel, Radio, RadioGroup, TextField } from "@mui/material";
import Button from "@mui/material/Button";
import { useSetAtom } from "jotai";
import type { ChangeEvent, FC , KeyboardEvent} from "react";
import type { ChangeEvent, FC, KeyboardEvent } from "react";
import { useRef, useState } from "react";

import type { TCommentOption, TWatchV3Metadata } from "@/@types/niconico";
import type { TCommentPickerMode } from "@/@types/niconico";
import type {
TCommentOption,
TCommentPickerMode,
TWatchV3Metadata,
} from "@/@types/niconico";
import type { TCommentItemRemote } from "@/@types/queue";
import { CommentOption } from "@/components/CommentOption";
import { isLoadingAtom, messageAtom } from "@/controller/atoms";
Expand Down
16 changes: 6 additions & 10 deletions src/controller/convert/convert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const Convert: FC = () => {
if (data.target !== "controller") return;
if (typeGuard.controller.message(data)) {
setMessage({
title: data.title || "未知のエラーが発生しました",
title: data.title ?? "未知のエラーが発生しました",
content: data.message,
});
}
Expand All @@ -168,12 +168,10 @@ const Convert: FC = () => {
<p>path: {movie.path}</p>
<p>duration: {movie.duration}</p>
{movie.type === "remote" && (
<>
<p>
source: https://nico.ms/{movie.ref.url} (
{movie.ref.format.type})
</p>
</>
<p>
source: https://nico.ms/{movie.ref.url} (
{movie.ref.format.type})
</p>
)}
</div>
<Button variant={"outlined"} size={"small"} onClick={onMovieClick}>
Expand All @@ -194,9 +192,7 @@ const Convert: FC = () => {
<p>path: {comment.path}</p>
<p>format: {comment.format}</p>
{comment.type === "remote" && (
<>
<p>source: https://nico.ms/{comment.ref.url}</p>
</>
<p>source: https://nico.ms/{comment.ref.url}</p>
)}
</div>
<Button variant={"outlined"} onClick={onCommentClick}>
Expand Down
2 changes: 1 addition & 1 deletion src/controller/movie-picker/local/local-movie-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const LocalMoviePicker: FC<Props> = ({ onChange }) => {
setIsLoading(false);
if (typeGuard.controller.message(data)) {
setMessage({
title: data.title || "未知のエラーが発生しました",
title: data.title ?? "未知のエラーが発生しました",
content: data.message,
});
return;
Expand Down
Loading

0 comments on commit 6c77a7b

Please sign in to comment.