forked from BenPaoDeXiaoZhi/spineExtension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
83 lines (83 loc) · 2.95 KB
/
Copy pathdeploy.js
File metadata and controls
83 lines (83 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { chromium } from 'playwright';
import fs from 'fs';
// function getVM(vm){
// console.log(vm)
// }
const pid = process.env.PROJECT_ID;
const token =
process.env.CCW_TOKEN || '000000000000000063c2807d669fa967f17f0000';
const uid = token.slice(16);
console.log('deploy to Project:', pid);
console.log('using uid:', uid);
try {
(async () => {
const browser = await chromium.launch();
// Create pages, interact with UI elements, assert values
const context = await browser.newContext();
let fdat = fs.readFileSync('./dist/extension.global.js', 'utf8');
console.log(fdat.slice(0,100)+"...");
await context.addCookies([
{
name: 'token',
value: token,
domain: '.ccw.site',
path: '/',
httpOnly: true,
},
{
name: 'cookie-user-id',
value: uid,
domain: '.ccw.site',
path: '/',
},
]);
await context.exposeFunction('log', (...dat) => {
console.log(...dat);
});
await context.exposeFunction('exit', async (ext = '') => {
console.log('exit');
await page.close();
await context.close();
await browser.close();
console.log('exited');
throw new Error('exited');
});
context.addInitScript((fdat) => {
console.log = console.warn = console.error = log;
window.onerror = function (message, source, lineno, colno, error) {
console.error(
`Error: ${message} at ${source}:${lineno}:${colno}`
);
// 进一步的处理逻辑
return true; // 阻止默认的错误处理
};
let vm;
const tid = setTimeout(
() => window.exit(document.body.innerHTML),
20000
);
const orig = Function.prototype.bind;
Function.prototype.bind = function (self2, ...args) {
if (self2?.runtime && self2.on) {
vm = self2;
Function.prototype.bind = orig;
window.log('vm trapped');
vm.on('PROJECT_LOADED', getAssets);
vm.on('PROJECT_LOAD_FAILED', log);
}
return orig.call(this, self2, ...args);
};
async function getAssets() {
window.log(vm.runtime.gandi.assets);
vm.updateGandiAssetData('extension.js', fdat);
clearTimeout(tid);
setTimeout(async () => {
await window.exit();
}, 10000);
}
}, fdat);
// Create a new page inside context.
const page = await context.newPage();
await page.goto('https://ccw.site/gandi/extension/' + pid);
})();
} catch (e) {}