Migrate only unique and non-default instruct prompts

This commit is contained in:
Cohee
2024-09-20 01:02:13 +03:00
parent 4e5a997e63
commit 4b235f0b31
2 changed files with 60 additions and 4 deletions

View File

@@ -218,6 +218,37 @@ function getContentIndex() {
return result;
}
/**
* Gets content by type and format.
* @param {string} type Type of content
* @param {'json'|'string'|'raw'} format Format of content
* @returns {string[]|Buffer[]} Array of content
*/
function getContentOfType(type, format) {
const contentIndex = getContentIndex();
const indexItems = contentIndex.filter((item) => item.type === type && item.folder);
const files = [];
for (const item of indexItems) {
if (!item.folder) {
continue;
}
const filePath = path.join(item.folder, item.filename);
const fileContent = fs.readFileSync(filePath);
switch (format) {
case 'json':
files.push(JSON.parse(fileContent.toString()));
break;
case 'string':
files.push(fileContent.toString());
break;
case 'raw':
files.push(fileContent);
break;
}
}
return files;
}
/**
* Gets the target directory for the specified asset type.
* @param {ContentType} type Asset type
@@ -724,5 +755,6 @@ module.exports = {
checkForNewContent,
getDefaultPresets,
getDefaultPresetFile,
getContentOfType,
router,
};