Skip to content

Commit

Permalink
op locations, dirnames, screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
steam0r committed Sep 18, 2024
1 parent 67d55dc commit 9aae281
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion shared/api/utils/shared_doc_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export default class SharedDocUtil extends SharedUtil
if (clearFiles || !this.cachedLookup.names) this.cachedLookup.names = {};
ops.forEach((op) =>
{
if (op.name && op.id)
if (op && op.name && op.id)
{
this.cachedLookup.ids[op.id] = op.name;
this.cachedLookup.names[op.name] = op.id;
Expand Down
1 change: 1 addition & 0 deletions shared/api/utils/shared_helper_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export default class SharedHelperUtil extends SharedUtil
{
if (!dir) dir = baseDir;
let results = [];
if (!fs.existsSync(dir)) return results;
let list = fs.readdirSync(dir);
list.forEach((file) =>
{
Expand Down
36 changes: 33 additions & 3 deletions shared/api/utils/shared_ops_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,11 @@ export default class SharedOpsUtil extends SharedUtil
cacheDocs.forEach((cacheDoc) =>
{
// keep this to update cache during runtime...
const cachedName = this.getOpIdByObjName(cacheDoc.name);
if (opNames.some((name) => { return cacheDoc.name.startsWith(name); })) allOpDocs.push(cacheDoc);
if (cacheDoc)
{
const cachedName = this.getOpIdByObjName(cacheDoc.name);
if (opNames.some((name) => { return cacheDoc.name.startsWith(name); })) allOpDocs.push(cacheDoc);
}
});
});
const newOpDocs = [];
Expand Down Expand Up @@ -2769,12 +2772,14 @@ export default class SharedOpsUtil extends SharedUtil
return { "problems": ["invalid op name" + opName] };
}
let basePath = this.getOpTargetDir(opName);
let jsonPath = this.getOpJsonPath(opName);
if (targetDir)
{
basePath = targetDir;
let opPath = path.join(basePath, this.getOpTargetDir(opName, true));
mkdirp.sync(opPath);
fn = path.join(opPath, this.getOpFileName(opName));
jsonPath = path.join(opPath, this.getOpJsonFilename(opName));
}
mkdirp.sync(basePath);

Expand Down Expand Up @@ -2828,7 +2833,7 @@ export default class SharedOpsUtil extends SharedUtil
result.coreLibs = newCoreLibNames;
}

jsonfile.writeFileSync(this.getOpJsonPath(opName), newJson, {
jsonfile.writeFileSync(jsonPath, newJson, {
"encoding": "utf-8",
"spaces": 4
});
Expand Down Expand Up @@ -3393,5 +3398,30 @@ export default class SharedOpsUtil extends SharedUtil
if (cb) cb(null, log, newJsonData);
return true;
}

getScreenshot(opName)
{
const p = this.getOpAbsolutePath(opName);
let buffer = " ";

try
{
buffer = fs.readFileSync(p + "screenshot.png", "binary");
}
catch (ex)
{
try
{
let fileName = "placeholder_dark.png";
const placeholderPath = path.join(this._cables.getPublicPath(), "/img/", fileName);
buffer = fs.readFileSync(placeholderPath);
}
catch (e)
{
this._log.error("error loading op screenshot and placeholder", opName);
}
}
return buffer;
}
}

0 comments on commit 9aae281

Please sign in to comment.