1
0
mirror of https://github.com/TheFunny/ArisuAutoSweeper synced 2026-06-10 00:24:51 +00:00

Upload code

This commit is contained in:
2023-11-01 15:33:35 +08:00
commit 6860f2eb72
415 changed files with 50990 additions and 0 deletions
@@ -0,0 +1,52 @@
import {webuiArgs, webuiPath} from '/@/config';
import {PyShell} from '/@/pyshell';
import type {CallbackFun} from '/@/coreService';
import logger from '/@/logger';
export const createAlas: CallbackFun = async ctx => {
let alas: PyShell | null = null;
try {
alas = new PyShell(webuiPath, webuiArgs);
} catch (e) {
ctx.onError(e);
}
alas?.on('error', function (err: string) {
if (!err) return;
logger.error('alas.error:' + err);
ctx.sendLaunchLog(err);
});
alas?.end(function (err: string) {
if (!err) return;
logger.info('alas.end:' + err);
ctx.sendLaunchLog(err);
throw err;
});
alas?.on('stdout', function (message) {
ctx.sendLaunchLog(message);
});
alas?.on('message', function (message) {
ctx.sendLaunchLog(message);
});
alas?.on('stderr', function (message: string) {
ctx.sendLaunchLog(message);
/**
* Receive logs, judge if Alas is ready
* For starlette backend, there will have:
* `INFO: Uvicorn running on http://0.0.0.0:22267 (Press CTRL+C to quit)`
* Or backend has started already
* `[Errno 10048] error while attempting to bind on address ('0.0.0.0', 22267): `
*/
if (message.includes('Application startup complete') || message.includes('bind on address')) {
alas?.removeAllListeners('stderr');
alas?.removeAllListeners('message');
alas?.removeAllListeners('stdout');
}
});
alas?.on('pythonError', err => {
ctx.onError('alas pythonError:' + err);
});
return alas;
};
@@ -0,0 +1,43 @@
import type {CallbackFun} from '/@/coreService';
import {PyShell} from '/@/pyshell';
import {installerArgs, installerPath} from '/@/config';
import {ALAS_RELAUNCH_ARGV} from '@common/constant/config';
import logger from '/@/logger';
export const createInstaller: CallbackFun = async (ctx, next) => {
if (process.argv.includes(ALAS_RELAUNCH_ARGV)) {
return next();
}
let installer: PyShell | null = null;
try {
installer = new PyShell(installerPath, installerArgs);
} catch (err) {
ctx.onError(err);
}
installer?.on('error', function (err: string) {
if (!err) return;
logger.error('installer.error:' + err);
ctx.sendLaunchLog(err);
});
installer?.end(function (err: string) {
if (!err) return;
logger.info('installer.end:' + err);
ctx.sendLaunchLog(err);
// throw err;
});
installer?.on('stdout', function (message) {
ctx.sendLaunchLog(message);
});
installer?.on('message', function (message) {
ctx.sendLaunchLog(message);
});
installer?.on('stderr', function (message: string) {
ctx.sendLaunchLog(message);
});
installer?.on('pythonError', err => {
ctx.onError('alas pythonError :' + err);
});
return installer;
};
@@ -0,0 +1,4 @@
import {createInstaller} from './createInstaller';
import {createAlas} from './createAlas';
export {createInstaller, createAlas};