Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,38 @@ app.use(bodyParser.urlencoded({
}))
app.use(bodyParser.json())

app.get("/", (req, res) => {
let html = fs.readFileSync(path.join(WORK_DIR, "guide.html")).toString()
let js = fs.readFileSync(path.join(WORK_DIR, "install-runtime.js")).toString()
html = html.replace("@@code@@", js)
res.send(html)
})
const _ip = getIPAdress();

app.get('/', (req, res) => {
let html = fs.readFileSync(path.join(WORK_DIR, 'guide.html')).toString();
let js = fs.readFileSync(path.join(WORK_DIR, 'install-runtime.js')).toString();

js = js.replace('*|IP_ADDRESS|*', `${_ip}:${HTTP_PORT}`);

// 从Scripts文件夹读取所有文件
let files = fs.readdirSync(SCRIPTS_DIR);
let filesStr = '';

for (const file of files) {
// 格式化文件名
filesStr += `'${file}',`;
}

js = js.replace('*|FILES|*', filesStr);

html = html.replace('@@code@@', js);

res.send(html);
});

app.get('/Scripts/:fileName', (req, res) => {
try {
let js = fs.readFileSync(path.join(SCRIPTS_DIR, req.params['fileName'])).toString();
res.send(js);
} catch (e) {
res.send('//访问文件错误');
}
});

app.get('/ping', (req, res) => {
console.log('[-] ping..')
Expand Down Expand Up @@ -117,7 +143,6 @@ function getIPAdress() {
}
}

const _ip = getIPAdress()
const _host = `http://${_ip}:${HTTP_PORT}`

console.log('[*] 「小件件」开发服务运行中')
Expand Down
4 changes: 2 additions & 2 deletions install-runtime.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const FILE_MGR = FileManager[module.filename.includes('Documents/iCloud~') ? 'iCloud' : 'local']();
await Promise.all(['「小件件」开发环境.js', '「源码」小组件示例.js'].map(async js => {
const REQ = new Request(`https://gitee.com/im3x/Scriptables/raw/v2-dev/Scripts/${encodeURIComponent(js)}`);
await Promise.all([*|FILES|*].map(async js => {
const REQ = new Request(`http://*|IP_ADDRESS|*/Scripts/${encodeURIComponent(js)}`);
const RES = await REQ.load();
FILE_MGR.write(FILE_MGR.joinPath(FILE_MGR.documentsDirectory(), js), RES);
}));
Expand Down