Skip to content

Commit

Permalink
feat: support special port when launch in binary
Browse files Browse the repository at this point in the history
  • Loading branch information
ltaoo committed Jun 23, 2023
1 parent 2477bc5 commit c6530b2
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 11 deletions.
7 changes: 6 additions & 1 deletion domains/aliyundrive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,12 @@ export class AliyunDriveClient {
}
async ping() {
// await this.ensure_initialized();
return this.request.post(API_HOST + "/adrive/v2/user/get", {});
const r = await this.request.post(API_HOST + "/adrive/v2/user/get", {});
if (r.error) {
console.log(r.error);
return Result.Err(r.error);
}
return Result.Ok(null);
}
/** 文件移入回收站 */
async delete_file(file_id: string) {
Expand Down
2 changes: 1 addition & 1 deletion domains/episode_file_processor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class EpisodeFileProcessor extends BaseDomain<TheTypesOfEvents> {
const existing_episode = existing_episode_res.data;

function log(...args: unknown[]) {
// if (!tv.name.includes("十八年后")) {
// if (!tv.name.includes("夏日")) {
// return;
// }
// console.log(...args);
Expand Down
1 change: 1 addition & 0 deletions domains/job/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class Job extends BaseDomain<TheTypesOfEvents> {
const { content: prev_content_str } = output;
// console.log("prev_content_str", prev_content_str, content, this.profile.output_id);
try {
// @todo 这里总是出错,Timeout 是为什么,怎么解决?
const r = await this.store.prisma.output.update({
where: {
id: this.profile.output_id,
Expand Down
7 changes: 4 additions & 3 deletions domains/searcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ export class MediaSearcher extends BaseDomain<TheTypesOfEvents> {
// }),
// })
// );
// log(`[${prefix}/${season_number}/${episode_number}]`, "准备添加剧集信息");
// console.log(`[${prefix}/${season_number}/${episode_number}]`, "准备添加剧集信息");
const r = await this.add_episode_from_parsed_episode({
parsed_tv,
parsed_season,
Expand Down Expand Up @@ -1085,7 +1085,7 @@ export class MediaSearcher extends BaseDomain<TheTypesOfEvents> {
}
return a;
})();
const movie_item = list[0];
const movie_item = matched;
const r = await this.get_movie_profile_with_tmdb_id({
tmdb_id: movie_item.id,
original_language: movie_item.original_language,
Expand All @@ -1110,7 +1110,7 @@ export class MediaSearcher extends BaseDomain<TheTypesOfEvents> {
return Result.Err(profile_res.error);
}
const profile = profile_res.data;
const { name, original_name, overview, poster_path, backdrop_path, popularity, vote_average, status } = profile;
const { name, original_name, overview, poster_path, backdrop_path, popularity, vote_average, air_date } = profile;
const { poster_path: uploaded_poster_path, backdrop_path: uploaded_backdrop_path } = await (async () => {
if (upload_image) {
return this.upload_tmdb_images({
Expand All @@ -1132,6 +1132,7 @@ export class MediaSearcher extends BaseDomain<TheTypesOfEvents> {
poster_path: uploaded_poster_path || null,
backdrop_path: uploaded_backdrop_path || null,
original_language: original_language || null,
air_date,
popularity,
vote_average,
});
Expand Down
19 changes: 16 additions & 3 deletions domains/tmdb/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,12 @@ export async function search_movie_in_tmdb(keyword: string, options: TMDBRequest
page: data.page,
total: data.total_results,
list: data.results.map((result) => {
const { title, original_title, backdrop_path, poster_path } = result;
const { title, original_title, backdrop_path, poster_path, release_date } = result;
return {
...result,
name: title,
original_name: original_title,
air_date: release_date,
...fix_TMDB_image_path({
backdrop_path,
poster_path,
Expand Down Expand Up @@ -582,14 +583,26 @@ export async function fetch_movie_profile(
if (result.error) {
return Result.Err(result.error);
}
const { overview, tagline, status, title, original_title, vote_average, poster_path, backdrop_path, popularity } =
result.data;
const {
overview,
tagline,
status,
title,
original_title,
vote_average,
release_date,
poster_path,
backdrop_path,
popularity,
} = result.data;
return Result.Ok({
id,
title,
original_title,
name: title,
original_name: original_title,
air_date: release_date,
release_date,
overview,
tagline,
status,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@family-flix/api",
"version": "1.2.0",
"version": "1.2.1",
"private": true,
"scripts": {
"dev": "node static.js & next dev --port 3200",
Expand Down
1 change: 1 addition & 0 deletions prisma/migrations/20230611135946_init/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ CREATE TABLE "ParsedSeason" (
"file_id" TEXT,
"file_name" TEXT,
"can_search" INTEGER DEFAULT 1,
"correct_season_number" TEXT,
"season_id" TEXT,
"parsed_tv_id" TEXT NOT NULL,
"drive_id" TEXT NOT NULL,
Expand Down
27 changes: 25 additions & 2 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ import fs from "fs/promises";

import { start } from "./commands/start";
import { setup } from "./commands/setup";
import { has_setup } from "./utils";
import { Application } from "./application";

function parse_argv(args: string[]) {
// const args = process.argv.slice(2);
const options: Record<string, string | boolean> = {};
args.forEach((arg) => {
if (arg.startsWith("--")) {
const [key, value] = arg.slice(2).split("=");
options[key] = value || true;
}
});
return options;
}

async function main() {
const app = new Application({ root_path: process.cwd() });
const args = parse_argv(process.argv);

console.log("应用信息");
// console.log("项目当前目录", app.root_path);
Expand All @@ -28,9 +40,20 @@ async function main() {
console.log("初始化失败", r.error.message);
return;
}
const DEFAULT_PORT = 3100;
const { port = DEFAULT_PORT } = args;
start({
dev: process.env.NODE_ENV !== "production",
port: 3100,
port: (() => {
if (typeof port === "boolean") {
return DEFAULT_PORT;
}
if (typeof port === "string") {
const n = Number(port);
return Number.isNaN(n) ? DEFAULT_PORT : n;
}
return port;
})(),
// pathname: admin === null ? "/setup" : "/admin",
pathname: "/admin",
assets: app.assets,
Expand Down

0 comments on commit c6530b2

Please sign in to comment.