Skip to content

Commit

Permalink
docs: 📝 use English annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
caorushizi committed Dec 19, 2024
1 parent 93617ff commit 59e02f3
Show file tree
Hide file tree
Showing 41 changed files with 175 additions and 175 deletions.
8 changes: 4 additions & 4 deletions packages/backend/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ async function startNodemon() {
consola.log(data.toString());
});

// 监听 stderr 数据事件
// Listen for stderr data events
nodemon.stderr?.on("data", (data) => {
consola.error(`stderr: ${data.toString()}`);
});

// 监听子进程的关闭事件
// Listens for closing events of the child process
nodemon.on("close", (code) => {
consola.log(`子进程退出,退出码 ${code}`);
});
Expand All @@ -80,7 +80,7 @@ async function buildTask() {
await esbuild.build(buildOptions());
}

// 开发环境
// Development environment
export const dev = gulp.series(clean, copy, watchTask, startNodemon);
// 构建打包
// Build packaging
export const build = gulp.series(buildClean, copy, buildTask);
6 changes: 3 additions & 3 deletions packages/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class ElectronApp extends Koa {
.use(this.router.allowedMethods());
this.use(serve(STATIC_DIR));

// 处理静态文件和前端路由的中间件
// Middleware that handles static files and front-end routing
this.use(async (ctx, next) => {
if (!ctx.path.startsWith("/api")) {
try {
Expand All @@ -70,9 +70,9 @@ export default class ElectronApp extends Koa {
});
}

// 如果重启后还有正在下载的视频,就将状态改成下载失败
// If there are still videos being downloaded after the restart, change the status to download failed
async resetDownloadStatus(): Promise<void> {
// 重启后如果还有 downloading 状态的数据, 全部重置为失败
// If data in the downloading state still fails after the restart, all downloads fail
const videos = await this.videoRepository.findWattingAndDownloadingVideos();
const videoIds = videos.map((video) => video.id);
await this.videoRepository.changeVideoStatus(
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/controller/DownloadController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export default class DownloadController implements Controller {
@post("download-items-now")
async downloadItemsNow(ctx: Context) {
const videos = ctx.request.body as Omit<DownloadItem, "id">[];
// 添加下载项
// Add download
const items = await this.downloaderService.addDownloadItems(videos);
// 开始下载
// Start downloading
items.forEach((item) => this.downloaderService.startDownload(item.id));
return items;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export function getLocalIP() {
const interfaces = os.networkInterfaces();
let localIP = "";

// 遍历网络接口
// Traverse the network interface
for (const key in interfaces) {
const iface = interfaces[key];
if (!iface) continue;

// 过滤出 IPv4 地址且非回环地址
// IPv4 addresses that are not loopback addresses are filtered out
const filteredIface = iface.filter(
(details) => details.family === "IPv4" && !details.internal,
);
Expand Down
32 changes: 16 additions & 16 deletions packages/backend/src/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,40 @@ declare interface WebSource {
}

declare interface AppStore {
// 本地存储地址
// Local storage address
local: string;
// 下载完成提示音
// Download completion tone
promptTone: boolean;
// 代理地址
// Proxy address
proxy: string;
// 是否开启代理
// Whether to enable agent
useProxy: boolean;
// 下载完成后删除原始文件
// Delete the original file after downloading
deleteSegments: boolean;
// 新窗口打开浏览器
// A new window opens the browser
openInNewWindow: boolean;
mainBounds?: Rectangle;
browserBounds?: Rectangle;
blockAds: boolean;
// 主题
// theme
theme: AppTheme;
// 使用浏览器插件
// Using browser plugins
useExtension: boolean;
// 是否使用手机UA
// Whether to use mobile UA
isMobile: boolean;
// 最大同时下载数
// Maximum number of simultaneous downloads
maxRunner: number;
// 语言
// Language
language: AppLanguage;
// 是否显示终端
// Show terminal or not
showTerminal: boolean;
// 隐私模式
// Privacy mode
privacy: boolean;
// 机器id
// Machine id
machineId: string;
// 下载代理设置
// Download proxy Settings
downloadProxySwitch: boolean;
// 自动更新
// Automatic update
autoUpgrade: boolean;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/backend/src/repository/VideoRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class VideoRepository {
) {}

async addVideo(video: Omit<DownloadItem, "id">) {
// 先判断有没有同名的视频
// Let's see if there's a video with the same name
const exist = await this.findVideoByName(video.name);
if (exist) {
throw new Error(i18n.t("videoExistsPleaseChangeName"));
Expand All @@ -34,7 +34,7 @@ export default class VideoRepository {
}

async addVideos(videos: Omit<DownloadItem, "id">[]) {
// 检查是否有同名的视频
// Check for videos with the same name
const names = videos.map((item) => item.name);
const existItems = await this.db.appDataSource
.getRepository(Video)
Expand All @@ -61,7 +61,7 @@ export default class VideoRepository {
return await this.db.manager.save(items);
}

// 编辑视频
// Edit video
async editVideo(video: DownloadItem) {
const item = await this.db.appDataSource
.getRepository(Video)
Expand All @@ -76,7 +76,7 @@ export default class VideoRepository {
return await this.db.manager.save(item);
}

// 查找所有视频
// Find all Videos
async findAllVideos() {
return await this.db.appDataSource.getRepository(Video).find({
order: {
Expand Down
26 changes: 13 additions & 13 deletions packages/backend/src/services/DownloadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import ConfigService from "./ConfigService.ts";
import path from "path";

interface DownloadContext {
// 是否为直播
// Whether it is live
isLive: boolean;
// 下载进度
// Download progress
percent: string;
// 下载速度
// Download speed
speed: string;
// 是否已经 ready
// Ready
ready: boolean;
}

Expand All @@ -52,7 +52,7 @@ interface Schema {
type: string;
}

// FIXME: 多语言正则表达式
// FIXME: Multilingual regular expressions
const processList: Schema[] = [
{
type: "m3u8",
Expand Down Expand Up @@ -201,15 +201,15 @@ export default class DownloadService extends EventEmitter {
} catch (err: any) {
if (err.message === "AbortError") {
this.logger.info(`taskId: ${task.id} stopped`);
// 下载暂停
// Download pause
await this.videoRepository.changeVideoStatus(
task.id,
DownloadStatus.Stopped,
);
this.emit("download-stop", task.id);
} else {
this.logger.error(`taskId: ${task.id} failed`, err);
// 下载失败
// Download failure
await this.videoRepository.changeVideoStatus(
task.id,
DownloadStatus.Failed,
Expand All @@ -219,18 +219,18 @@ export default class DownloadService extends EventEmitter {
} finally {
this.removeTask(task.id);

// 传输完成
// Transmission complete
if (this.queue.length === 0 && this.active.length === 0) {
// this.emit("download-finish");
}
}
}

removeTask(id: number) {
// 处理当前正在活动的任务
// Process the currently active task
const doneId = this.active.findIndex((i) => i.id === id);
this.active.splice(doneId, 1);
// 处理完成的任务
// Process completed tasks
if (this.active.length < this.limit) {
this.runTask();
}
Expand Down Expand Up @@ -356,16 +356,16 @@ export default class DownloadService extends EventEmitter {
const percentReg = RegExp(consoleReg.percent, "g");

const onMessage = (ctx: DownloadContext, message: string) => {
// 解析是否为直播资源
// Resolve whether it is a live resource
if (isLiveReg.test(message)) {
ctx.isLive = true;
}
// 解析下载进度
// Parse download progress
const [, percent] = percentReg.exec(message) || [];
if (percent && Number(ctx.percent || 0) < Number(percent)) {
ctx.percent = percent;
}
// 解析下载速度
// Parsing download speed
const [, speed] = speedReg.exec(message) || [];
if (speed) {
ctx.speed = speed;
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/services/DownloaderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class DownloaderService {
) {}

async startDownload(vid: number) {
// 查找将要下载的视频
// Find the video you want to download
const video = await this.videoRepository.findVideo(vid);
const { name, url, headers, type, folder } = video;
const { local, deleteSegments } = await this.store.getConfig();
Expand All @@ -39,9 +39,9 @@ export default class DownloaderService {
}

async downloadNow(video: Omit<DownloadItem, "id">) {
// 添加下载项
// Add download
const item = await this.addDownloadItem(video);
// 开始下载
// Start downloading
await this.startDownload(item.id);
return item;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/vendor/SocketIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class SocketIO implements Vendor {
};

receiveMessage = async (id: number, message: string) => {
// 将日志写入数据库中
// Write the log to the database
await this.videoRepository.appendDownloadLog(id, message);
};
}
6 changes: 3 additions & 3 deletions packages/main/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function copyBin() {
}

async function chmodBin() {
// 遍历文件夹下的所有文件,将文件的权限设置为 777
// Go through all the files in the folder and set the permissions on the files to 777
if (isWin) return;

const files = globSync(mainResolve("app/bin/*"));
Expand Down Expand Up @@ -115,9 +115,9 @@ async function pack() {
await builder.build({ config });
}

// 开发环境
// Development environment
export const dev = gulp.series(devCopy, chmodBin, watchTask);
// 构建打包
// Build packaging
export const build = gulp.series(clean, buildCopy, chmodBin, buildTask);
// release
export const release = gulp.series(pack);
4 changes: 2 additions & 2 deletions packages/main/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ export default class ElectronApp {
tray.setContextMenu(contextMenu);
}

// 如果重启后还有正在下载的视频,就将状态改成下载失败
// If there are still videos being downloaded after the restart, change the status to download failed
async resetDownloadStatus(): Promise<void> {
// 重启后如果还有 downloading 状态的数据, 全部重置为失败
// If data in the downloading state still fails after the restart, all downloads fail
const videos = await this.videoRepository.findWattingAndDownloadingVideos();
const videoIds = videos.map((video) => video.id);
await this.videoRepository.changeVideoStatus(
Expand Down
16 changes: 8 additions & 8 deletions packages/main/src/controller/DownloadController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ export default class DownloadController implements Controller {
@handle("add-download-item")
async addDownloadItem(e: IpcMainEvent, video: Omit<DownloadItem, "id">) {
const item = await this.videoRepository.addVideo(video);
// 这里向页面发送消息,通知页面更新
// This sends a message to the page notifying it of the update
this.mainWindow.send("download-item-notifier", item);
return item;
}

@handle("add-download-items")
async addDownloadItems(e: IpcMainEvent, videos: Omit<DownloadItem, "id">[]) {
const items = await this.videoRepository.addVideos(videos);
// 这里向页面发送消息,通知页面更新
// This sends a message to the page notifying it of the update
this.mainWindow.send("download-item-notifier", items);
return items;
}
Expand All @@ -75,18 +75,18 @@ export default class DownloadController implements Controller {

@handle("download-now")
async downloadNow(e: IpcMainEvent, video: Omit<DownloadItem, "id">) {
// 添加下载项
// Add download
const item = await this.addDownloadItem(e, video);
// 开始下载
// Start downloading
await this.startDownload(e, item.id);
return item;
}

@handle("download-items-now")
async downloadItemsNow(e: IpcMainEvent, videos: Omit<DownloadItem, "id">[]) {
// 添加下载项
// Add download
const items = await this.addDownloadItems(e, videos);
// 开始下载
// Start downloading
items.forEach((item) => this.startDownload(e, item.id));
return items;
}
Expand Down Expand Up @@ -120,12 +120,12 @@ export default class DownloadController implements Controller {

@handle("start-download")
async startDownload(e: IpcMainEvent, vid: number) {
// 查找将要下载的视频
// Find the video you want to download
const video = await this.videoRepository.findVideo(vid);
const { name, url, headers, type, folder } = video;
const local = this.store.get("local");

// 从配置中添加参数
// Add parameters from the configuration
const deleteSegments = this.store.get("deleteSegments");

const task: Task = {
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/controller/HomeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ export default class HomeController implements Controller {

@handle("combine-to-home-page")
async combineToHomePage() {
// 关闭浏览器窗口
// Close browser window
this.browserWindow.hideWindow();
// 修改设置中的属性
// Modify the properties in the Settings
this.store.set("openInNewWindow", false);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/core/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class ProtocolService {
let filePath = join(__dirname, "../renderer", pathName);
const fileExist = await pathExists(filePath);
if (!fileExist) {
// 如果没有找到文件,直接返回 index.html react history 模式
// If the file is not found, return index.html directly, react history mode
filePath = join(__dirname, "../renderer/index.html");
}
const mimeType = mime.lookup(filePath);
Expand Down
Loading

0 comments on commit 59e02f3

Please sign in to comment.