Skip to content

Commit

Permalink
import multiple files at once
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoweiprc committed Dec 6, 2024
1 parent 8868780 commit cf9dae5
Show file tree
Hide file tree
Showing 12 changed files with 748 additions and 700 deletions.
431 changes: 212 additions & 219 deletions packages/insomnia/src/common/import.ts

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions packages/insomnia/src/main/ipc/extractPostmanDataDump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,33 @@ export default async function extractPostmanDataDumpHandler(_event: unknown, dat
};
}

const collectionList: string[] = [];
const envList: string[] = [];
interface FileDetail {
contentStr: string;
oriFileName: string;
}

const collectionList: FileDetail[] = [];
const envList: FileDetail[] = [];

// get collections and environments listed in archive.json
try {
files.filter(file => file !== archiveJsonFile).forEach(file => {
const id = path.basename(file.path, '.json');
const oriFileName = path.basename(file.path);
if (id in archiveJsonData.collection) {
collectionList.push(file.data.toString());
collectionList.push({
contentStr: file.data.toString(),
oriFileName,
});
} else if (id in archiveJsonData.environment) {
const fileContentStr = file.data.toString();
const fileJson = JSON.parse(fileContentStr);
// Set the scope to environment, because it's not set in the file
fileJson._postman_variable_scope = 'environment';
envList.push(JSON.stringify(fileJson));
envList.push({
contentStr: JSON.stringify(fileJson),
oriFileName,
});
}
});
} catch (err) {
Expand Down
1 change: 0 additions & 1 deletion packages/insomnia/src/models/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface BaseWorkspace {
description: string;
certificates?: any; // deprecated
scope: 'design' | 'collection' | 'mock-server' | 'environment';
workspaceUuid?: string;
}

export type WorkspaceScope = BaseWorkspace['scope'];
Expand Down
8 changes: 2 additions & 6 deletions packages/insomnia/src/plugins/context/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export const init = (activeProjectId?: string) => ({
uri,
});

await scanResources({
content,
});
await scanResources([content]);

await importResourcesToProject({
projectId: activeProjectId,
Expand All @@ -47,9 +45,7 @@ export const init = (activeProjectId?: string) => ({
if (!activeProjectId) {
return;
}
await scanResources({
content,
});
await scanResources([content]);

await importResourcesToProject({
projectId: activeProjectId,
Expand Down
Loading

0 comments on commit cf9dae5

Please sign in to comment.