Skip to content

Commit

Permalink
fix: Type match error
Browse files Browse the repository at this point in the history
  • Loading branch information
empty-233 committed Jan 23, 2024
1 parent 5b74fa3 commit 29c07d1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
44 changes: 35 additions & 9 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,27 @@ const anime_offline_database: animeOfflineDatabaseList = readFile(
`${anime_offline_database_path}/anime-offline-database.json`
);

//判断是否一致
/**
* 判断是否一致
* @param objects 元数据
* @param value 匹配值
* @returns 匹配结果
*/
const findIfExists = (
objects: Array<animeOfflineDatabaseData>,
value: string
value: string,
matchField: keyof animeOfflineDatabaseData
) => {
return objects.filter((obj) =>
obj.synonyms.some((element) => element == value)
);
return objects.filter((obj) => {
const fieldValue = obj[matchField];
if (Array.isArray(fieldValue)) {
// If fieldValue is an array, use the some() method to check if the array contains the value.
return fieldValue.some((element) => element == value);
} else {
// If fieldValue is not an array, check if it is equal to the value.
return fieldValue == value;
}
});
};

/**
Expand Down Expand Up @@ -83,11 +96,24 @@ let animeData: Root = {
};
bangumi_data_paths.map((path) => {
const bangumi_data: Array<bangumiDataList> = readFile(path);
let datas:Array<Data>=[]
let datas: Array<Data> = [];
bangumi_data.map((bangumiData) => {
const aods = findIfExists(anime_offline_database.data, bangumiData.title);
const aods = findIfExists(
anime_offline_database.data,
bangumiData.title,
"synonyms"
);
if (aods.length !== 0) {
const aod = aods[aods.length - 1];
const typeMatching = findIfExists(
aods,
bangumiData.type.toUpperCase(),
"type"
);
// 如果type匹配成功就使用type匹配结果
const aod =
typeMatching.length !== 0
? typeMatching[typeMatching.length - 1]
: aods[aods.length - 1];
aod.relations.map((url) => {
const result = splitUrl(url);
bangumiData.sites.push({
Expand All @@ -107,7 +133,7 @@ bangumi_data_paths.map((path) => {
thumbnail: aod.thumbnail,
synonyms: aod.synonyms,
};
datas.push(data)
datas.push(data);
animeData.data.push(data);
}
});
Expand Down
2 changes: 1 addition & 1 deletion utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const cloneRepository = (
try {
const repoExists = fs.existsSync(destinationPath);
if (repoExists) {
execSync(`git -C ${destinationPath} pull --depth 1`);
execSync(`git -C ${destinationPath} pull --rebase --depth 1`);
} else {
execSync(`git clone --depth 1 ${repositoryUrl} ${destinationPath}`);
}
Expand Down

0 comments on commit 29c07d1

Please sign in to comment.