可以读取 workspace 了

This commit is contained in:
frostime 2023-05-22 22:20:40 +08:00
parent c29ea97240
commit 9007a64178

View file

@ -10,34 +10,43 @@ const targetDir = '';
// const targetDir = `H:\\SiYuanDevSpace\\data\\plugins`; // const targetDir = `H:\\SiYuanDevSpace\\data\\plugins`;
//******************************************************************************************** //********************************************************************************************
const log = console.log;
async function getSiYuanDir(token) { async function getSiYuanDir() {
let url = 'http://127.0.0.1:6806/api/system/getConf'; let url = 'http://127.0.0.1:6806/api/system/getWorkspaces';
let header = { let header = {
"Authorization": `Token ${token}`, // "Authorization": `Token ${token}`,
"Content-Type": "application/json", "Content-Type": "application/json",
} }
let conf = {};
try { try {
let conf = await fetch(url, { let response = await fetch(url, {
method: 'POST', method: 'POST',
headers: header headers: header
}); });
console.log(conf); if (response.ok) {
} catch (e) { conf = await response.json();
console.log(e); } else {
log(`HTTP-Error: ${response.status}`);
process.exit(1); process.exit(1);
} }
} catch (e) {
log("Error:", e);
process.exit(1);
}
return conf.data;
} }
if (targetDir === '') { if (targetDir === '') {
await getSiYuanDir('es7zy9zewgibc6dt'); let res = await getSiYuanDir();
log(res);
process.exit(0); process.exit(0);
} }
//Check //Check
if (!fs.existsSync(targetDir)) { if (!fs.existsSync(targetDir)) {
console.log(`Failed! plugin directory not exists: "${targetDir}"`); log(`Failed! plugin directory not exists: "${targetDir}"`);
console.log(`Please set the plugin directory in scripts/make_dev_link.js`); log(`Please set the plugin directory in scripts/make_dev_link.js`);
process.exit(1); process.exit(1);
} }
@ -52,7 +61,7 @@ if (!fs.existsSync('./plugin.json')) {
const plugin = JSON.parse(fs.readFileSync('./plugin.json', 'utf8')); const plugin = JSON.parse(fs.readFileSync('./plugin.json', 'utf8'));
const name = plugin?.name; const name = plugin?.name;
if (!name || name === '') { if (!name || name === '') {
console.log('Failed! Please set plugin name in plugin.json'); log('Failed! Please set plugin name in plugin.json');
process.exit(1); process.exit(1);
} }
@ -66,11 +75,11 @@ if (!fs.existsSync(devDir)) {
const targetPath = `${targetDir}/${name}`; const targetPath = `${targetDir}/${name}`;
//如果已经存在,就退出 //如果已经存在,就退出
if (fs.existsSync(targetPath)) { if (fs.existsSync(targetPath)) {
console.log('Failed! Target directory already exists'); log('Failed! Target directory already exists');
process.exit(1); process.exit(1);
} }
//创建软链接 //创建软链接
fs.symlinkSync(`${process.cwd()}/dev`, targetPath, 'junction'); fs.symlinkSync(`${process.cwd()}/dev`, targetPath, 'junction');
console.log(`Done! Created symlink ${targetPath}`); log(`Done! Created symlink ${targetPath}`);