Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static async getThumbnail(json: any, directory: Directory, filePath?: string): Promise {
let fp: string = filePath || directory.directoryPath;
fp = Utils.normaliseFilePath(fp);
const thumbnailPattern: string = fp + '/thumb.*';
const thumbnails: string[] = await glob(thumbnailPattern);
if (thumbnails.length) {
// there's alrady a thumbnail in the directory, add it to the canvas
console.log(chalk.green('found thumbnail for: ') + fp);
let thumbnail: string = thumbnails[0];
const thumbnailJson: any = Utils.cloneJson(thumbnailBoilerplate);
thumbnailJson[0].id = Utils.mergePaths(directory.url, Utils.getVirtualFilePath(thumbnail, directory));
json.thumbnail = thumbnailJson;
} else if (directory.generateThumbs) {
// there isn't a thumbnail in the directory, so we'll need to generate it.
// if debugging: jimp item.getitem is not a function
// generate thumbnail
if (json.items && json.items.length && json.items[0].items) {
// find an annotation with a painting motivation of type image.
const items: any[] = json.items[0].items;
public async read(): Promise {
// canvases are directories starting with an underscore
const canvasesPattern: string = this.directoryPath + '/_*';
const canvases: string[] = await glob(canvasesPattern, {
ignore: [
'**/*.yml',
'**/thumb.*'
]
});
// sort canvases
canvases.sort((a, b) => {
return Utils.compare(a, b);
});
await Promise.all(canvases.map(async (canvas: string) => {
console.log(chalk.green('creating canvas for: ') + canvas);
this.items.push(new Canvas(canvas, this));
}));
it('should output one JS bundle', async() => {
expect(await glob.promise(path.join(CONTEXT.publicDir, './**/index.*.bundle.js'))).to.have.lengthOf(1);
});
private async processGames(folder: string) {
const gamesFolder: string = path.resolve(folder, this.manifestRegEx);
logger.info('SteamCrawler', `Looking for Steam games manifests in ${gamesFolder}.`);
try {
const files: string[] = await glob(gamesFolder);
if (!files.length) {
logger.info('SteamCrawler', `No Steam games found in this directory.`);
return [];
}
const gameManifests: any[] = (await Promise.all(files.map(async (appManifest: any) => (await parseAcf(appManifest)).appState))).filter(
(appManifest: any) => {
const found: boolean =
this.playableGames.filter((playableGame: any) => parseInt(appManifest.appid) === playableGame.details.steamId).length > 0;
if (found) {
logger.info('SteamCrawler', `Steam game ${appManifest.name} is already a playable game.`);
}
return !found;
}
);
return gameManifests.map((gameManifest: any) => {
logger.info('SteamCrawler', `Steam game ${gameManifest.name} (Steam ID ${gameManifest.appid}) found.`);
private async loadLocales() {
const langFilesFolder: string = getEnvFolder('config/lang');
const langFilesPaths = await glob(`${langFilesFolder}/*`);
return await Promise.all(langFilesPaths.map(async (langFilePath: string) => ({
locale: path.basename(langFilePath, '.json'),
messages: flatten(await fs.readJson(langFilePath))
})));
}
public async search(emulatedConfig: any) {
this.emulatedConfig = emulatedConfig;
logger.info('EmulatedCrawler', `Searching roms folders in ${this.emulatedConfig.romsFolder}.`);
const aliveEmulators: any[] = this.emulatedConfig.aliveEmulators.map((aliveEmulator: any) => ({
...this.emulatedConfig.emulators.filter((emulator: any) => emulator.id === aliveEmulator.id)[0],
...aliveEmulator
}));
const folders: string[] = await glob(`${this.emulatedConfig.romsFolder}/*`);
this.folders = folders.map((folder: string) => ({
...this.emulatedConfig.platforms.filter((platform: any) => platform.folder.toUpperCase() === path.basename(folder).toUpperCase())[0],
folder
})).filter((platform: any) => platform.id).map((platform: any) => {
return ({
emulator: aliveEmulators.filter((aliveEmulator: any) => aliveEmulator.platforms.includes(platform.id))[0],
folder: platform.folder
});
}).filter((folderData: any) => {
if (!folderData.emulator)
return false;
logger.info('EmulatedCrawler', `Roms folder ${folderData.folder} found and bound to ${folderData.emulator.name}.`);
return true;
});
return new GamesCollection(await this.analyzeFolders());
}
(async () => {
const files = await glob.promise('public/**/*');
files.map((file) => {
const fileName = file.substr('public/'.length);
const ext = path.extname(file);
if (fs.lstatSync(file).isDirectory()) return;
if (ext === '.map') return;
const isImage = ext === '.jpg' || ext === '.png' || ext === '.gif' || ext === '.bmp' || ext === '.webp' || ext === '.jpx' || ext === '.jp2';
const isHtml = ext === '.html';
try {
storage
.bucket(bucketName)
.upload(file, {
destination: fileName,
gzip: !isImage,