mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-26 16:52:06 +05:30
Improve file search algorithm
This commit is contained in:
parent
b25e888781
commit
7bd45e7ada
@ -1,8 +1,6 @@
|
||||
/* eslint-env node */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
const path = require('path');
|
||||
|
||||
require('dotenv').config();
|
||||
|
||||
const { env } = process;
|
||||
@ -17,7 +15,7 @@ module.exports = {
|
||||
projectId: 350687,
|
||||
filePath: 'accounts/site.json',
|
||||
sourceLang: 'en',
|
||||
basePath: path.resolve(`${__dirname}/packages/app/i18n`),
|
||||
basePath: `${__dirname}/packages/app/i18n`,
|
||||
minApproved: 80, // Minimal ready percent before translation can be published
|
||||
},
|
||||
};
|
||||
|
@ -132,12 +132,19 @@ async function findFileId(filePath: string, branchId?: number): Promise<number |
|
||||
directoryId = (await findDirectoryId(dirPath, branchId)) || null;
|
||||
}
|
||||
|
||||
// We're receiving files list without branch filter until https://github.com/crowdin/crowdin-api-client-js/issues/63
|
||||
// will be resolved. But right now it doesn't matter because for each branch directories will have its own ids,
|
||||
// so if the file is stored into the some directory, algorithm will find correct file.
|
||||
const { data: filesResponse } = await crowdin.sourceFilesApi.listProjectFiles(PROJECT_ID /*, branchId*/);
|
||||
// When the branchId and directoryId aren't specified the list returned recursively,
|
||||
// but if one of this param is specified, the list contains only the specified parent.
|
||||
//
|
||||
// Directories ids for each branch are different, so directoryId is already ensures
|
||||
// that the file will be searched in the correct branch
|
||||
const { data: filesResponse } = await crowdin.sourceFilesApi.listProjectFiles(
|
||||
PROJECT_ID,
|
||||
directoryId === null ? branchId : undefined,
|
||||
directoryId || undefined, // directory ID can't be 0, but can be null
|
||||
);
|
||||
const files = filesResponse.map((fileData) => fileData.data);
|
||||
|
||||
// Compare directoryId since when the file is placed in the root
|
||||
return files.find((file) => file.directoryId === directoryId && file.name === fileName)?.id;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user