Skip to content

Commit

Permalink
fix: some dependencies not found after package
Browse files Browse the repository at this point in the history
  • Loading branch information
ltaoo committed Jun 10, 2023
1 parent d91babc commit f26fbdd
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion domains/analysis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 1. 遍历云盘分析文件名,获取到剧集、电影
* 2. 将获取到的剧集和电影在 TMDB 上搜索海报、简介等信息
*/
import { Handler } from "mitt";
import type { Handler } from "mitt";

import { BaseDomain } from "@/domains/base";
import { EpisodeFileProcessor } from "@/domains/episode_file_processor";
Expand Down
2 changes: 1 addition & 1 deletion domains/article/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file 一篇文章的抽象节点
* 为了消息提示
*/
import { Handler } from "mitt";
import type { Handler } from "mitt";

import { BaseDomain } from "@/domains/base";
import dayjs from "dayjs";
Expand Down
8 changes: 6 additions & 2 deletions domains/base.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/**
* 注册的监听器
*/
import { Result } from "@/types";
import mitt, { EventType, Handler } from "mitt";
import type { EventType, Handler } from "mitt";

import mitt from "@/modules/mitt";
// import { Result } from "@/types";

// import { Log } from './log';

let _uid = 0;
Expand All @@ -28,6 +31,7 @@ export class BaseDomain<Events extends Record<EventType, unknown>> {
_name: string = "BaseDomain";
debug: boolean = false;

// @ts-ignore
_emitter = mitt<BaseDomainEvents<Events>>();
listeners: (() => void)[] = [];

Expand Down
2 changes: 1 addition & 1 deletion domains/folder_differ/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file 对比两个文件夹的差异
*/
import { Handler } from "mitt";
import type { Handler } from "mitt";

import { AliyunDriveFile, AliyunDriveFolder } from "@/domains/folder";
import { ArticleLineNode, ArticleListItemNode, ArticleListNode, ArticleTextNode } from "@/domains/article";
Expand Down
10 changes: 5 additions & 5 deletions domains/job/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { throttle } from "lodash/fp";
import { throttle } from "lodash";
import dayjs from "dayjs";

import { BaseDomain } from "@/domains/base";
Expand Down Expand Up @@ -128,7 +128,7 @@ export class Job extends BaseDomain<TheTypesOfEvents> {

this.output.on_write(this.update_content);
}
update_content = throttle(2000, async () => {
update_content = throttle(async () => {
const content = this.output.to_json();
this.output.clear();
if (content.length === 0) {
Expand Down Expand Up @@ -156,9 +156,9 @@ export class Job extends BaseDomain<TheTypesOfEvents> {
} catch (err) {
console.log(err);
}
});
}, 2000);
/** check need pause the task */
check_need_pause = throttle(3000, async () => {
check_need_pause = throttle(async () => {
const r = await this.store.find_task({ id: this.id });
if (r.error) {
return Result.Ok(false);
Expand All @@ -171,7 +171,7 @@ export class Job extends BaseDomain<TheTypesOfEvents> {
return Result.Ok(true);
}
return Result.Ok(false);
});
}, 3000);
async fetch_profile() {
// return { ...this.profile };
const r1 = await this.store.prisma.async_task.findFirst({
Expand Down
2 changes: 1 addition & 1 deletion domains/resource_sync_task/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file 电视剧资源同步任务
*/
import { Handler } from "mitt";
import type { Handler } from "mitt";

import { BaseDomain } from "@/domains/base";
import { DifferEffect, DiffTypes, FolderDiffer } from "@/domains/folder_differ";
Expand Down
2 changes: 1 addition & 1 deletion domains/searcher/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file 影视剧搜索
*/
import { Handler } from "mitt";
import type { Handler } from "mitt";

import { BaseDomain } from "@/domains/base";
import { TMDBClient } from "@/domains/tmdb";
Expand Down
8 changes: 4 additions & 4 deletions domains/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export class User {
*/
static async New(token: string | undefined, store: DatabaseStore) {
if (!token) {
return Result.Err("缺少 token");
return Result.Err("缺少 token", 900);
}
const r = await parse_token({
token,
secret: User.SECRET,
});
if (r.error) {
return Result.Err(r.error);
return Result.Err(r.error.message);
}
const id = r.data.id as UserUniqueID;
const existing = await store.prisma.user.findFirst({
Expand All @@ -60,7 +60,7 @@ export class User {
},
});
if (!existing) {
return Result.Err("无效的 token");
return Result.Err("无效的 token", 900);
}
const { settings } = existing;
// 要不要生成一个新的 token?
Expand Down Expand Up @@ -252,7 +252,7 @@ export class User {
qiniu_access_token: qiniu_access_token ?? undefined,
qiniu_secret_token: qiniu_secret_token ?? undefined,
qiniu_scope: qiniu_scope ?? undefined,
tmdb_token: tmdb_token ?? 'c2e5d34999e27f8e0ef18421aa5dec38',
tmdb_token: tmdb_token ?? "c2e5d34999e27f8e0ef18421aa5dec38",
assets: assets ?? "./public",
};
})();
Expand Down
2 changes: 1 addition & 1 deletion domains/walker/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file 文件夹遍历器
*/
import { Handler } from "mitt";
import type { Handler } from "mitt";

import { AliyunDriveFile, AliyunDriveFolder } from "@/domains/folder";
import { BaseDomain } from "@/domains/base";
Expand Down
4 changes: 2 additions & 2 deletions pages/api/admin/user/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { NextApiRequest, NextApiResponse } from "next";

import { User } from "@/domains/user";
import { BaseApiResp } from "@/types";
import { BaseApiResp, Result } from "@/types";
import { response_error_factory } from "@/utils/backend";
import { store } from "@/store";

Expand All @@ -17,7 +17,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
}
const t_res = await User.New(token, store);
if (t_res.error) {
return e(t_res);
return e(Result.Err(t_res, t_res.code));
}
const { id } = t_res.data;
res.status(200).json({
Expand Down
8 changes: 8 additions & 0 deletions scripts/ncc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const modules = [
name: "axios",
pathname: "axios/dist/node/axios.cjs",
},
{
name: "mitt",
pathname: "mitt/dist/mitt.js",
},
{
name: "lodash",
pathname: "lodash/lodash.js",
},
{
name: "uuid",
pathname: "uuid/dist/index.js",
Expand Down
8 changes: 7 additions & 1 deletion scripts/pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ async function run() {
prismaClientPkg.version = "1.0.0";
fs.writeFileSync(".prisma/client/package.json", JSON.stringify(prismaClientPkg));
}
await pkg.exec(["./index.js", "--config=scripts/pkg.json", "--target=macos", "--compress=GZip", "--out-path=bin"]);
await pkg.exec([
"./index.js",
"--config=scripts/pkg.json",
// "--targets=node16-macos-x64,node16-win-arm64,node16-linux-arm64",
"--compress=GZip",
"--out-path=bin",
]);
}

run();
6 changes: 2 additions & 4 deletions scripts/pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
"../modules/**/*",
"../node_modules/@prisma",
"../node_modules/.prisma",
"../node_modules/dayjs"
"../node_modules/dayjs",
"../node_modules/lodash/**/*"
],
"scripts": ["modules/**/*"]
},
"dependencies": {
"@peculiar/webcrypto": "^1.4.3",
"dayjs": "^1.11.7",
"joi": "^17.9.1",
"jsonwebtoken": "^9.0.0",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"mitt": "^3.0.0",
"nzh": "^1.0.8",
"qiniu": "^7.8.0"
}
Expand Down
3 changes: 3 additions & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const Result = {
Err: <T>(message: string | Error | Result<null>, code?: number | string, data: unknown = null) => {
const result = {
data,
/**
* @deprecated 把 error 类型改为 BizError 后取 error.code
*/
code,
error: (() => {
if (typeof message === "string") {
Expand Down

0 comments on commit f26fbdd

Please sign in to comment.