mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-19 13:47:19 -04:00
fix: support specific importer when import from curl (#9197)
This commit is contained in:
@@ -135,7 +135,7 @@ const main: Window['main'] = {
|
||||
insecureReadFile: options => ipcRenderer.invoke('insecureReadFile', options),
|
||||
insecureReadFileWithEncoding: options => ipcRenderer.invoke('insecureReadFileWithEncoding', options),
|
||||
secureReadFile: options => ipcRenderer.invoke('secureReadFile', options),
|
||||
parseImport: options => ipcRenderer.invoke('parseImport', options),
|
||||
parseImport: (...args) => ipcRenderer.invoke('parseImport', ...args),
|
||||
readDir: options => ipcRenderer.invoke('readDir', options),
|
||||
lintSpec: options => ipcRenderer.invoke('lintSpec', options),
|
||||
on: (channel, listener) => {
|
||||
|
||||
@@ -18,9 +18,19 @@ export interface ConvertResult {
|
||||
};
|
||||
}
|
||||
|
||||
export const convert = async (importEntry: ImportEntry) => {
|
||||
const importers = (await import('./importers')).importers;
|
||||
export const convert = async (
|
||||
importEntry: ImportEntry,
|
||||
{
|
||||
importerId,
|
||||
}: {
|
||||
importerId?: string;
|
||||
} = {},
|
||||
) => {
|
||||
let importers = (await import('./importers')).importers;
|
||||
const errMsgList: string[] = [];
|
||||
if (importerId) {
|
||||
importers = importers.filter(i => i.id === importerId);
|
||||
}
|
||||
for (const importer of importers) {
|
||||
let resources;
|
||||
if (importer.acceptFilePath === true) {
|
||||
|
||||
@@ -66,7 +66,7 @@ export interface RendererToMainBridgeAPI {
|
||||
cancelAuthorizationInDefaultBrowser: typeof cancelAuthorizationInDefaultBrowser;
|
||||
setMenuBarVisibility: (visible: boolean) => void;
|
||||
installPlugin: typeof installPlugin;
|
||||
parseImport: (options: { contentStr: string }) => Promise<{ data: { resources: models.BaseModel[] } }>;
|
||||
parseImport: typeof convert;
|
||||
writeFile: (options: { path: string; content: string }) => Promise<string>;
|
||||
secureReadFile: (options: { path: string }) => Promise<string>;
|
||||
insecureReadFile: (options: { path: string }) => Promise<string>;
|
||||
@@ -162,8 +162,8 @@ export function registerMainHandlers() {
|
||||
return cancelAuthorizationInDefaultBrowser(options);
|
||||
},
|
||||
);
|
||||
ipcMainHandle('parseImport', async (_, options: { contentStr: string }) => {
|
||||
return convert(options);
|
||||
ipcMainHandle('parseImport', async (_, ...args: Parameters<typeof convert>) => {
|
||||
return convert(...args);
|
||||
});
|
||||
ipcMainHandle('writeFile', async (_, options: { path: string; content: string }) => {
|
||||
try {
|
||||
|
||||
@@ -21,9 +21,14 @@ export const PasteCurlModal = ({
|
||||
useEffect(() => {
|
||||
async function parseCurlToRequest() {
|
||||
try {
|
||||
const { data } = await window.main.parseImport({
|
||||
contentStr: defaultValue || '',
|
||||
});
|
||||
const { data } = await window.main.parseImport(
|
||||
{
|
||||
contentStr: defaultValue || '',
|
||||
},
|
||||
{
|
||||
importerId: 'curl',
|
||||
},
|
||||
);
|
||||
const { resources } = data;
|
||||
const importedRequest = resources[0];
|
||||
setIsValid(true);
|
||||
@@ -53,12 +58,19 @@ export const PasteCurlModal = ({
|
||||
defaultValue={defaultValue}
|
||||
onChange={async value => {
|
||||
if (!value) {
|
||||
setIsValid(false);
|
||||
setReq({});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const { data } = await window.main.parseImport({
|
||||
contentStr: value,
|
||||
});
|
||||
const { data } = await window.main.parseImport(
|
||||
{
|
||||
contentStr: value,
|
||||
},
|
||||
{
|
||||
importerId: 'curl',
|
||||
},
|
||||
);
|
||||
const { resources } = data;
|
||||
const importedRequest = resources[0];
|
||||
setIsValid(true);
|
||||
|
||||
Reference in New Issue
Block a user