Skip to content

Commit

Permalink
move assetpath handling to shared code
Browse files Browse the repository at this point in the history
  • Loading branch information
steam0r committed Jun 12, 2024
1 parent 6153bd6 commit a4cee52
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
95 changes: 95 additions & 0 deletions shared/api/utils/shared_projects_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export default class SharedProjectsUtil extends SharedUtil
return path.join(this._cables.getAssetPath(), String(projectId));
}

getAssetPathUrl(projectId)
{
return path.join("/assets/", projectId, "/");
}

getScreenShotPath(pId)
{
pId = sanitizeFileName("" + pId);
Expand Down Expand Up @@ -174,4 +179,94 @@ export default class SharedProjectsUtil extends SharedUtil
}
return assetPorts;
}

getAvailableLibs(project)
{
let _libs = [];
if (project)
{
_libs = this.getAssetLibs(project);
}
_libs = _libs.concat(fs.readdirSync(this._cables.getLibsPath()));
const libs = [];
for (let i = 0; i < _libs.length; i++)
{
let skip = false;
if (_libs[i].endsWith(".js"))
{
const libName = path.parse(_libs[i]);
if (libName)
{
let jsonName = path.join(this._cables.getLibsPath(), libName.name);
jsonName += ".json";
if (fs.existsSync(jsonName))
{
const json = JSON.parse(fs.readFileSync(jsonName));
if (json.hidden)
{
skip = true;
}
}
}
if (!skip)
{
libs.push(_libs[i]);
}
}
}
return libs;
}

getCoreLibs()
{
const _coreLibs = fs.readdirSync(this._cables.getCoreLibsPath());
const coreLibs = [];
for (let i = 0; i < _coreLibs.length; i++)
{
const coreFilename = _coreLibs[i];
if (coreFilename.endsWith(".js"))
{
coreLibs.push(coreFilename.split(".")[0]);
}
}
return coreLibs;
}

getAssetLibs(project)
{
if (!project) return [];
const libs = [];
const assetPath = this.getAssetPath(project._id);
if (fs.existsSync(assetPath))
{
let _libs = fs.readdirSync(assetPath);
for (let i = 0; i < _libs.length; i++)
{
let skip = false;
if (_libs[i].endsWith(".js"))
{
const libName = path.parse(_libs[i]);
if (libName)
{
let jsonName = path.join(this._cables.getLibsPath(), libName.name);
jsonName += ".json";
if (fs.existsSync(jsonName))
{
const json = JSON.parse(fs.readFileSync(jsonName));
if (json.hidden)
{
skip = true;
}
}
}
if (!skip)
{
libs.push(path.join("/assets", String(project._id), _libs[i]));
}
}
}
}

return libs;
}
}
3 changes: 1 addition & 2 deletions shared/client/src/modaldialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export default class ModalDialog extends Events
if (autoOpen) this.show();

ele.byId("modalclose").style.display = "block";

if (window.gui) gui.currentModal = this;
}

Expand Down Expand Up @@ -250,7 +249,7 @@ export default class ModalDialog extends Events

this._addListeners();

CABLES.UI.hideToolTip();
if (CABLES && CABLES.UI) CABLES.UI.hideToolTip();

this.emitEvent("onShow", this);
}
Expand Down

0 comments on commit a4cee52

Please sign in to comment.