Skip to content

Commit

Permalink
feat/v0.4.1 (#281)
Browse files Browse the repository at this point in the history
* fix: import dataType problem

* refactor: eletronmanin and extionsionschange code optimize

* fix: bug repairs

* refactor: electron main and extensionschange optimize

* fix: import formdata bug

* test: env e2e

* refactor: resolve review

* style: test status bar

* wip: merge yzaio

* fix: env select hover

* fix: test error&&chat GPT length error

* style: environment error

* fix: env select boxshadow

* fix: content-type match bodyType error

* feat: 0.4.1

---------

Co-authored-by: sunzhouyang <sunzhouyang@eolink.com>
  • Loading branch information
scarqin and sunzhouyang committed Mar 22, 2023
1 parent 06bd93e commit 59a3c84
Show file tree
Hide file tree
Showing 60 changed files with 666 additions and 430 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcat",
"version": "0.4.0",
"version": "0.4.1",
"main": "out/app/electron-main/main.js",
"description": "A lightweight, extensible API tool",
"homepage": "https://github.com/Postcatlab/postcat.git",
Expand Down
154 changes: 90 additions & 64 deletions src/app/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import { app, BrowserWindow, ipcMain } from 'electron';
import Store from 'electron-store';
import { LanguageService } from 'pc/app/electron-main/language.service';
import { MockServer } from 'pc/platform/node/mock-server';
import {
GET_EXT_TABS,
GET_FEATURE,
GET_MOCK_URL,
GET_MODULE,
GET_MODULES,
GET_SIDEBAR_VIEW,
GET_SIDEBAR_VIEWS,
GET_WEBSOCKET_PORT,
INSTALL_MODULE,
LOGIN_WITH,
UNINSTALL_MODULE
} from 'pc/shared/electron-main/constant';
import portfinder from 'portfinder';

import { UnitWorkerModule } from '../../node/test-server/electron/main';
Expand Down Expand Up @@ -195,73 +208,86 @@ try {
}
});
let loginWindow = null;
// 这里可以封装成类+方法匹配调用,不用多个if else
['on', 'handle'].forEach(eventName =>
ipcMain[eventName]('eo-sync', async (event, arg) => {
let returnValue: any;
if (arg.action === 'getModules') {
returnValue = moduleManager.getModules();
} else if (arg.action === 'getModule') {
returnValue = moduleManager.getModule(arg.data.id);
} else if (arg.action === 'installModule') {
const data = await moduleManager.installExt(arg.data);
returnValue = Object.assign(data, { modules: moduleManager.getModules() });
} else if (arg.action === 'uninstallModule') {
const data = await moduleManager.uninstall(arg.data);
returnValue = Object.assign(data, { modules: moduleManager.getModules() });
} else if (arg.action === 'getExtensionPackage') {
returnValue = await moduleManager.getExtensionPackage(arg.data.feature, arg.data.params);
} else if (arg.action === 'getFeature') {
returnValue = moduleManager.getFeature(arg.data.featureKey);
} else if (arg.action === 'getMockUrl') {
// 获取mock服务地址
returnValue = mockServer.getMockUrl();
} else if (arg.action === 'getWebsocketPort') {
// 获取websocket服务端口
returnValue = websocketPort;
} else if (arg.action === 'getExtTabs') {
returnValue = moduleManager.getExtTabs(arg.data.extName);
} else if (arg.action === 'loginWith') {
// * It is eletron, open a new window for login
if (loginWindow) {
loginWindow.destroy();
loginWindow = null;
}
loginWindow = new BrowserWindow({
width: 990,
height: 655,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: false,
contextIsolation: false,
preload: path.join(__dirname, '../../platform/electron-browser/preload.js')
}
});
loginWindow.loadURL(arg.data.url);

//* Watch the login result
loginWindow.webContents.on('did-navigate', ($event, url = '') => {
const isError = url.includes('request-errors');
const isSuccess = url.includes('code=');
if (isError || isSuccess) {
loginWindow?.destroy();
loginWindow = null;
const querys = new URLSearchParams(url.split('?')?.[1]);
eoBrowserWindow.win.webContents.send('thirdLoginCallback', {
isSuccess: isSuccess,
code: querys?.get('code')
});
}
});
const getModules = () => Promise.resolve(moduleManager.getModules());

const getModule = arg => Promise.resolve(moduleManager.getModule(arg.data.id));

const installModule = async arg => {
const data = await moduleManager.installExt(arg.data);
return Object.assign(data, { modules: moduleManager.getModules() });
};

const uninstallModule = async arg => {
const data = await moduleManager.uninstall(arg.data);
return Object.assign(data, { modules: moduleManager.getModules() });
};

const getFeature = arg => Promise.resolve(moduleManager.getFeature(arg.data.featureKey));

const getMockUrl = () => Promise.resolve(mockServer.getMockUrl());

const getWebsocketPort = () => Promise.resolve(websocketPort);

const getExtTabs = arg => Promise.resolve(moduleManager.getExtTabs(arg.data.extName));

const loginWith = arg => {
if (loginWindow) {
loginWindow.destroy();
loginWindow = null;
}
loginWindow = new BrowserWindow({
width: 990,
height: 655,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: false,
contextIsolation: false,
preload: path.join(__dirname, '../../platform/electron-browser/preload.js')
}
});
loginWindow.loadURL(arg.data.url);

returnValue = '';
} else if (arg.action === 'getSidebarView') {
returnValue = moduleManager.getSidebarView(arg.data.extName);
} else if (arg.action === 'getSidebarViews') {
returnValue = moduleManager.getSidebarViews();
} else {
returnValue = 'Invalid data';
//* Watch the login result
loginWindow.webContents.on('did-navigate', ($event, url = '') => {
const isError = url.includes('request-errors');
const isSuccess = url.includes('code=');
if (isError || isSuccess) {
loginWindow?.destroy();
loginWindow = null;
const querys = new URLSearchParams(url.split('?')?.[1]);
eoBrowserWindow.win.webContents.send('thirdLoginCallback', {
isSuccess: isSuccess,
code: querys?.get('code')
});
}
});

return Promise.resolve('');
};

const getSidebarView = arg => Promise.resolve(moduleManager.getSidebarView(arg.data.extName));

const getSidebarViews = () => Promise.resolve(moduleManager.getSidebarViews());

const action = {
[GET_MODULES]: getModules,
[GET_MODULE]: getModule,
[INSTALL_MODULE]: installModule,
[UNINSTALL_MODULE]: uninstallModule,
[GET_FEATURE]: getFeature,
[GET_MOCK_URL]: getMockUrl,
[GET_WEBSOCKET_PORT]: getWebsocketPort,
[GET_EXT_TABS]: getExtTabs,
// * It is eletron, open a new window for login
[LOGIN_WITH]: loginWith,
[GET_SIDEBAR_VIEW]: getSidebarView,
[GET_SIDEBAR_VIEWS]: getSidebarViews
};

['on', 'handle'].forEach(eventName =>
ipcMain[eventName]('eo-sync', async (event, arg) => {
let returnValue = Object.keys(action).includes(arg.action) ? await action[arg.action](arg) : 'Invalid data';
event.returnValue = returnValue;
return returnValue;
})
Expand Down
1 change: 1 addition & 0 deletions src/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"eo-ng-table": "0.1.14",
"eo-ng-tabs": "0.1.11",
"eo-ng-tree": "0.1.16",
"gpt3-tokenizer": "1.1.5",
"is-xml": "0.1.0",
"js-beautify": "1.14.7",
"lodash-es": "4.17.21",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
.message-content {
padding: 1rem;
border-radius: 0.5rem;
min-width: fit-content;
max-width: 400px;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ export class EoMonacoEditorComponent implements AfterViewInit, OnInit, OnChanges
if (val === this.$$code) {
return;
}

let code = val;
try {
if (typeof val === 'object') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ExtensionService } from 'pc/browser/src/app/services/extensions/extensi
import { Message, MessageService } from 'pc/browser/src/app/services/message';
import { ApiService } from 'pc/browser/src/app/services/storage/api.service';
import { TraceService } from 'pc/browser/src/app/services/trace.service';
import { EXPORT_API } from 'pc/browser/src/app/shared/constans/featureName';
import { ExtensionChange } from 'pc/browser/src/app/shared/decorators';
import { FeatureInfo } from 'pc/browser/src/app/shared/models/extension-manager';
import StorageUtil from 'pc/browser/src/app/shared/utils/storage/storage.utils';
import { StoreService } from 'pc/browser/src/app/store/state.service';
Expand Down Expand Up @@ -32,17 +34,11 @@ export class ExportApiComponent implements OnInit {
) {}
ngOnInit(): void {
this.initData();
this.messageService
.get()
.pipe(takeUntil(this.destroy$))
.subscribe((inArg: Message) => {
if (inArg.type === 'extensionsChange') {
this.initData();
}
});
}
initData = () => {
this.featureMap = this.extensionService.getValidExtensionsByFature('exportAPI');
@ExtensionChange(EXPORT_API, true)
initData() {
console.log('initData');
this.featureMap = this.extensionService.getValidExtensionsByFature(EXPORT_API);
this.supportList = [];
this.featureMap?.forEach((data: FeatureInfo, key: string) => {
this.supportList.push({
Expand All @@ -55,7 +51,7 @@ export class ExportApiComponent implements OnInit {
if (!(this.currentExtension && this.supportList.find(val => val.key === this.currentExtension))) {
this.currentExtension = key || '';
}
};
}
submit(callback: () => boolean) {
this.export(callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Message, MessageService } from 'pc/browser/src/app/services/message';
import { ApiService } from 'pc/browser/src/app/services/storage/api.service';
import { parseAndCheckCollections, parseAndCheckEnv } from 'pc/browser/src/app/services/storage/db/validate/validate';
import { TraceService } from 'pc/browser/src/app/services/trace.service';
import { IMPORT_API } from 'pc/browser/src/app/shared/constans/featureName';
import { ExtensionChange } from 'pc/browser/src/app/shared/decorators';
import { FeatureInfo } from 'pc/browser/src/app/shared/models/extension-manager';
import { StoreService } from 'pc/browser/src/app/store/state.service';
import { Subject } from 'rxjs';
Expand Down Expand Up @@ -76,14 +78,12 @@ export class ImportApiComponent implements OnInit {
this.messageService
.get()
.pipe(takeUntil(this.destroy$))
.subscribe((inArg: Message) => {
if (inArg.type === 'extensionsChange') {
this.initData();
}
});
.subscribe((inArg: Message) => {});
}
initData = () => {
this.featureMap = this.extensionService.getValidExtensionsByFature('importAPI');

@ExtensionChange(IMPORT_API, true)
initData() {
this.featureMap = this.extensionService.getValidExtensionsByFature(IMPORT_API);
this.supportList = [];
this.featureMap?.forEach((data: FeatureInfo, key: string) => {
this.supportList.push({
Expand All @@ -96,7 +96,7 @@ export class ImportApiComponent implements OnInit {
if (!(this.currentExtension && this.supportList.find(val => val.key === this.currentExtension))) {
this.currentExtension = key || '';
}
};
}
uploadChange(data) {
this.uploadData = data;
}
Expand All @@ -116,6 +116,7 @@ export class ImportApiComponent implements OnInit {
const [data, err] = module[action](content);
console.log('import data', window.structuredClone?.(data));
if (err) {
this.eoMessage.error(err.msg);
console.error(err.msg);
callback(false);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { has } from 'lodash-es';
import { ExtensionService } from 'pc/browser/src/app/services/extensions/extension.service';
import { Message, MessageService } from 'pc/browser/src/app/services/message';
import { ApiService } from 'pc/browser/src/app/services/storage/api.service';
import { PUSH_API } from 'pc/browser/src/app/shared/constans/featureName';
import { ExtensionChange } from 'pc/browser/src/app/shared/decorators';
import { FeatureInfo } from 'pc/browser/src/app/shared/models/extension-manager';
import { Subject, takeUntil } from 'rxjs';

Expand Down Expand Up @@ -31,26 +33,29 @@ export class PushApiComponent implements OnInit {
this.messageService
.get()
.pipe(takeUntil(this.destroy$))
.subscribe((inArg: Message) => {
if (inArg.type === 'extensionsChange') {
this.initData();
}
});
.subscribe((inArg: Message) => {});
}
initData = () => {
this.featureMap = this.extensionService.getValidExtensionsByFature('pushAPI');

@ExtensionChange(PUSH_API, true)
initData() {
this.featureMap = this.extensionService.getValidExtensionsByFature(PUSH_API);
this.supportList = [];
this.featureMap?.forEach((data: FeatureInfo, key: string) => {
this.supportList.push({
key,
...data
});
});
{
const { key } = this.supportList?.at(0);
// {
// const { key } = this.supportList?.at(0);
// this.currentExtension = key || '';
// }
if (!this.supportList.length) return;
const { key } = this.supportList.at(0);
if (!(this.currentExtension && this.supportList.find(val => val.key === this.currentExtension))) {
this.currentExtension = key || '';
}
};
}
async submit(callback) {
const feature = this.featureMap.get(this.currentExtension);
if (!feature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ export class ExtensionSelectComponent {
observer.complete();
return;
}
parserJsonFile(file).then((result: { name: string }) => {
this.filename = result.name;
this.uploadChange.emit(result);
observer.complete();
});
parserJsonFile(file)
.then((result: { name: string }) => {
this.filename = result.name;
this.uploadChange.emit(result);
observer.complete();
})
.catch(err => {
this.message.error(err);
});
});
}
Loading

0 comments on commit 59a3c84

Please sign in to comment.