Files
minisrv/zefie_wtvp_minisrv/diskmap_gen.js
zefie 1165b245ce v0.9.33
- numerous bug fixes
 - wtv-mail system
 - user account updates
 - viewergen alpha (experimental webtv viewer patcher on pc_service)
 - implement wtv-favorites with huge help from @JarHead4
 - add wtv-ticket store api
 - Bump vm2 from 3.9.5 to 3.9.7 in /zefie_wtvp_minisrv
 - fix bf0app default rom
 - Add wtv-1800 service to wtv-1800:/noflash
 - handle webtvism:
   - allow get/post variables to be the same name multiple times
   - rather than overwrite, the server will now change the variable from a string to an array.
 - Rewrite script processing a bit
   - Instead of using eval() we now use a proper VM Context
   - As a result, any scripting errors will now give a more useful filename and line number.
   - However, some things may break, if they are dependant on variables we are not allowing in the context.
 - BREAKING CHANGES:
   - `ssid_sessions[socket.ssid]` is now `session_data`
   - `require` is no longer allowed in user scripts
 - add star service
 - change how we handle modules for services in the VM
 - fixed wtv-disk:/sync always failed the first time
 - implement production-like wtv-star handling (when a service port becomes unavailable, it requests the url over the wtv-star port to show an error page)
 - renamed WTVDownloadList.js to WTVDisk.js
 - a bit more work on WTVNews (created class)
 - probably more stuff I can't remember
2022-11-29 08:29:25 -05:00

93 lines
3.5 KiB
JavaScript

const process = require('process');
const fs = require('fs');
const path = require('path');
var { WTVShared, clientShowAlert } = require(classPath + "/WTVShared.js");
const wtvshared = new WTVShared(); // creates minisrv_config
var minisrv_config = wtvshared.getMiniSrvConfig(); // snatches minisrv_config
// primitive recursive diskmap generator, usage:
// node diskmap_gen.js path_in_servicevault diskmap_name wtvdest [service_name]
// service_name defaults to wtv-disk
// will create a primitive diskmap you can then edit it as you need
// example: node diskmap_gen.js content/Demo/ Demo.json DealerDemo file://Disk/Demo/
if (process.argv.length < 6) {
console.error("Usage:", process.argv[0], process.argv[1], "path_in_service_vault", "diskmap_name", "wtv_file_dest", "groupname", "[service_name]");
console.error("Example:", process.argv[0], process.argv[1], "content/Demo/ Demo.json DealerDemo file://Disk/Demo/");
process.exit(1);
}
var service_vault_subdir = process.argv[2];
var out_file = process.argv[3];
var group_name = process.argv[4];
var client_dest = process.argv[5];
if (process.argv.length >= 7) var service_name = process.argv[6];
else service_name = "wtv-disk";
// find which service_vault the files are in
// nothing fancy, won't support generating a list across multiple vaults
// so be sure to choose ONE vault to keep all the files in before scanning
// Can be any vault, and after the scan you could technically move files across vaults
// so long as they are on the same service still
var service_vault = null;
var service_vault_dir = null;
if (minisrv_config.config.ServiceVaults) {
Object.keys(minisrv_config.config.ServiceVaults).forEach(function (k) {
if (service_vault_dir) return;
var test = wtvshared.makeSafePath(wtvshared.returnAbsolutePath(minisrv_config.config.ServiceVaults[k]), service_name + path.sep + service_vault_subdir);
console.log(" * Looking for", test);
if (fs.existsSync(test)) {
console.log(" * Found", test);
service_vault = wtvshared.makeSafePath(wtvshared.returnAbsolutePath(minisrv_config.config.ServiceVaults[k]), service_name);
service_vault_dir = test;
}
})
}
if (!service_vault) {
console.error("Could not find", service_vault_subdir, "in any configured Service Vaults!");
process.exit(1);
}
const recursiveDirList = function (dirPath, arrayOfFiles = null) {
files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(function (file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = recursiveDirList(dirPath + "/" + file, arrayOfFiles)
} else {
arrayOfFiles.push(path.join(dirPath, "/", file))
}
})
return arrayOfFiles
}
var fileList = recursiveDirList(service_vault_dir);
if (fileList.length > 0) {
var diskmap = {};
diskmap[group_name] = {};
if (client_dest.substring(client_dest.length - 1, 1) != '/') client_dest += '/';
diskmap[group_name].base = client_dest;
diskmap[group_name].location = service_vault_subdir;
diskmap[group_name].files = [];
fileList.forEach(function (v) {
diskmap[group_name].files.push({ "file": v.replace(service_vault_dir, client_dest).replace(new RegExp('\\' + path.sep, 'g'), '/') });
});
// diskmap[group_name].files = diskmap_files;
fs.writeFileSync(out_file,JSON.stringify(diskmap, null, "\t"));
} else {
throw ("No files found in", service_vault);
}