Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async installPlugin(pluginPkgs: ZanProxyMac.IPluginPkg[]) {
const pluginManager = Container.get(PluginService);
let pluginsAllInstalled = true;
const installedPlugins = pluginManager.getPlugins();
for (const plugin of pluginPkgs) {
// 检查插件是否已经安装
const hasInstalled = installedPlugins.filter(i => i.name === plugin.name).length > 0;
if (hasInstalled) {
continue;
}
pluginsAllInstalled = false;
// 未安装插件则安装对应的插件
await pluginManager.add(plugin.name, { registry: plugin.registry });
}
if (!pluginsAllInstalled) {
showNotify({
title: 'Zan Proxy 通知',
body: '内部插件初始化安装完成,请重新启动',
data.payerId = user2.id
await this.costService.create(user2.id, data)
j += 1
}
let k = 30
while (k < 45) {
data.name = "Cost" + k
data.payerId = user3.id
await this.costService.create(user3.id, data)
k += 1
}
}
}
Container.get(Seeds)
.create()
.then(() => {
console.log("Seeds created 🌳")
process.exit()
})
.catch(err => {
console.log(err.message)
process.exit()
})
const syncRemoteHosts = async () => {
console.log('开始同步远程Host文件');
const hostService = Container.get(HostService);
const hostFileList = hostService.getHostFileList();
for (const hostFile of hostFileList) {
if (!hostFile.meta || hostFile.meta.local === true || !hostFile.meta.url) {
continue;
}
console.info(`同步远程Host${hostFile.name}中`);
try {
await hostService.importRemoteHostFile(hostFile.meta.url);
console.info(`同步远程Host${hostFile.name}成功`);
} catch (e) {
console.error(`同步远程Host${hostFile.name}失败`);
}
}
console.log('同步远程Host文件结束');
};
(async () => {
initGa();
await syncStorageService.init();
await localStorageService.init();
await localeService.init();
Container.set(ILocalStorageService, localStorageService);
Container.set(ISyncStorageService, syncStorageService);
Container.get(IConfigService).load();
Container.get(IPowerpackService).startup();
const app = dva({
namespacePrefixWarning: false,
history: createHashHistory(),
onError: e => {
(e as any).preventDefault();
message.destroy();
message.error(e.message);
},
});
app.use(createLoading());
if (config.createLogger) {
app.use(
createLogger({
predicate: (_: Function, { type }: Action) => {
return (
import "reflect-metadata"
import Container, { Service } from "typedi"
import { CostJob } from "./modules/cost/cost.job"
import { createDbConnection } from "./db"
@Service()
class Workers {
constructor(private readonly costJob: CostJob) {}
async work() {
await createDbConnection()
await this.costJob.work()
}
}
Container.get(Workers)
.work()
.then(() => console.log("Workers running 🏃"))
.catch(err => console.log(err.message))
constructor() {
const deps =
this.log = Container.get(LogFactory).for(this)
this.options = Container.get(Configurer).get('redis');
const {host, port, db} = this.options;
this.log.info('Starting redis client. Server: %s:%s/%d', host, port, db);
this.client = new Redis(this.options);
//happen only once
this.client.on('ready', () => {
this.log.info('redis ready');
});
//happen each time when reconnected
this.client.on('connect', () => {
this.log.info('redis connected');
});
this.client.on('disconnect', () => {
const Changelog: React.FC = () => {
const { locale } = useSelector(({ userPreference: { locale } }: GlobalStore) => {
return {
locale,
};
});
const configService = Container.get(IConfigService);
const workLocale = useObserver(() => {
let workLocale = 'en-US';
if (configService.config?.privacyLocale.some(o => o === locale)) {
workLocale = locale;
}
return workLocale;
});
const { loading, result: changelog } = useAsync(
() => request.get(`${config.resourceHost}/privacy/PRIVACY.${workLocale}.md`),
[]
);
if (loading || !changelog) {
return ;
},
{
name: 'host-and-rule-files',
manager: Container.get(HostAndRuleFilesManager),
},
{
name: 'workspace',
manager: Container.get(WorkspaceManager),
},
{
name: 'tray',
manager: Container.get(TrayManager),
},
{
name: 'renderer-loader',
manager: Container.get(RendererLoaderManager),
},
];
/**
* 外部插件数组
*
* @private
* @type {BaseManager[]}
* @memberof Application
*/
private externalPlugins: IPlugin[] = [];
/**
* 全部插件数组
*
* @readonly
import fs from 'fs-extra';
import { each } from 'lodash';
import path from 'path';
import Container from 'typedi';
import { AppInfoService } from './services';
const proxyDataDir = Container.get(AppInfoService).proxyDataDir;
function rm(p: string) {
if (fs.existsSync(p)) {
fs.removeSync(p);
}
}
function move(source: string, target: string, transformer?: (text: string) => string) {
if (fs.existsSync(source)) {
let text = fs.readFileSync(source, 'utf-8');
if (transformer) {
text = transformer(text);
}
fs.writeFileSync(target, text, 'utf-8');
fs.removeSync(source);
}
/**
* 内置的插件
*
* @private
* @type {IPlugin[]}
* @memberof Application
*/
private builtInPlugin: IPlugin[] = [
{
name: 'zan-proxy-plugin',
manager: Container.get(ZanPorxyPluginManager),
},
{
name: 'app-data',
manager: Container.get(AppDataManager),
},
{
name: 'host-and-rule-files',
manager: Container.get(HostAndRuleFilesManager),
},
{
name: 'workspace',
manager: Container.get(WorkspaceManager),
},
{
name: 'tray',
manager: Container.get(TrayManager),
},
{
name: 'renderer-loader',
manager: Container.get(RendererLoaderManager),