-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support modfiy movie name that is incorrect
- Loading branch information
Showing
11 changed files
with
165 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* @file 获取未识别的电影 | ||
*/ | ||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { BaseApiResp } from "@/types"; | ||
import { response_error_factory } from "@/utils/backend"; | ||
import { store } from "@/store"; | ||
import { User } from "@/domains/user"; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<BaseApiResp<unknown>>) { | ||
const e = response_error_factory(res); | ||
const { query } = req; | ||
const { page: page_str = "1", page_size: page_size_str = "20" } = query as Partial<{ | ||
page: string; | ||
page_size: string; | ||
}>; | ||
const { authorization } = req.headers; | ||
const t_res = await User.New(authorization, store); | ||
if (t_res.error) { | ||
return e(t_res); | ||
} | ||
const { id: user_id } = t_res.data; | ||
const page = Number(page_str); | ||
const page_size = Number(page_size_str); | ||
|
||
const where: NonNullable<Parameters<typeof store.prisma.parsed_movie.findMany>[number]>["where"] = { | ||
movie_id: null, | ||
user_id, | ||
}; | ||
const list = await store.prisma.parsed_movie.findMany({ | ||
where, | ||
orderBy: { | ||
created: "desc", | ||
}, | ||
take: page_size, | ||
skip: (page - 1) * page_size, | ||
}); | ||
const count = await store.prisma.parsed_movie.count({ where }); | ||
res.status(200).json({ | ||
code: 0, | ||
msg: "", | ||
data: { | ||
page, | ||
page_size, | ||
total: count, | ||
no_more: list.length + (page - 1) * page_size >= count, | ||
list: list.map((parsed_season) => { | ||
const { id, name, original_name, file_name } = parsed_season; | ||
return { | ||
id, | ||
name, | ||
original_name, | ||
file_name, | ||
}; | ||
}), | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* @file 更新未识别的电影名称 | ||
*/ | ||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { User } from "@/domains/user"; | ||
import { BaseApiResp } from "@/types"; | ||
import { response_error_factory } from "@/utils/backend"; | ||
import { app, store } from "@/store"; | ||
import { MediaSearcher } from "@/domains/searcher"; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<BaseApiResp<unknown>>) { | ||
const e = response_error_factory(res); | ||
const { authorization } = req.headers; | ||
const { id } = req.query as Partial<{ id: string }>; | ||
const { name } = req.body as Partial<{ name: string }>; | ||
|
||
if (!id) { | ||
return e("缺少电影 id"); | ||
} | ||
if (!name) { | ||
return e("缺少正确的电影名称"); | ||
} | ||
|
||
const t_res = await User.New(authorization, store); | ||
if (t_res.error) { | ||
return e(t_res); | ||
} | ||
const user = t_res.data; | ||
const parsed_movie = await store.prisma.parsed_movie.findFirst({ | ||
where: { | ||
id, | ||
user_id: user.id, | ||
}, | ||
}); | ||
if (!parsed_movie) { | ||
return e("没有匹配的季"); | ||
} | ||
|
||
const { drive_id } = parsed_movie; | ||
if (parsed_movie.name === name) { | ||
return e(`名称已经是 '${name}' 了`); | ||
} | ||
const searcher_res = await MediaSearcher.New({ | ||
user_id: user.id, | ||
drive_id, | ||
tmdb_token: user.settings.tmdb_token, | ||
assets: app.assets, | ||
force: true, | ||
store, | ||
}); | ||
if (searcher_res.error) { | ||
return e(searcher_res); | ||
} | ||
const searcher = searcher_res.data; | ||
const r = await searcher.add_movie_from_parsed_movie({ | ||
parsed_movie: { | ||
...parsed_movie, | ||
correct_name: name, | ||
}, | ||
}); | ||
if (r.error) { | ||
return e(r.error); | ||
} | ||
const r2 = await store.update_parsed_movie(parsed_movie.id, { | ||
correct_name: name, | ||
}); | ||
if (r2.error) { | ||
return e(r2); | ||
} | ||
res.status(200).json({ code: 0, msg: "修改成功", data: null }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters