Merge branch 'master' into unify-extensions

This commit is contained in:
Andrew Bastin
2020-02-19 21:14:57 -05:00
committed by GitHub
7 changed files with 142 additions and 12 deletions

View File

@@ -120,20 +120,40 @@ export default {
reader.onload = event => {
let content = event.target.result;
let collections = JSON.parse(content);
this.$store.commit("postwoman/replaceCollections", collections);
if (collections[0]) {
let [ name, folders, requests ] = Object.keys(collections[0])
if (name === 'name' && folders === 'folders' && requests === 'requests') {
// Do nothing
}
} else if (collections.info && collections.info.schema.includes('v2.1.0')) {
collections = this.parsePostmanCollection(collections)
} else {
return this.failedImport();
}
this.$store.commit("postwoman/importCollections", collections);
this.fileImported();
};
reader.readAsText(this.$refs.inputChooseFileToReplaceWith.files[0]);
this.fileImported();
},
importFromJSON() {
let reader = new FileReader();
reader.onload = event => {
let content = event.target.result;
let collections = JSON.parse(content);
if (collections[0]) {
let [ name, folders, requests ] = Object.keys(collections[0])
if (name === 'name' && folders === 'folders' && requests === 'requests') {
// Do nothing
}
} else if (collections.info && collections.info.schema.includes('v2.1.0')) {
collections = this.parsePostmanCollection(collections);
} else {
return this.failedImport();
}
this.$store.commit("postwoman/importCollections", collections);
this.fileImported();
};
reader.readAsText(this.$refs.inputChooseFileToImportFrom.files[0]);
this.fileImported();
},
exportJSON() {
let text = this.collectionJson;
@@ -161,6 +181,114 @@ export default {
this.$toast.info(this.$t("file_imported"), {
icon: "folder_shared"
});
},
failedImport() {
this.$toast.error(this.$t("import_failed"), {
icon: "error"
});
},
parsePostmanCollection(collection, folders = true) {
let postwomanCollection = folders ? [{
"name": "",
"folders": [],
"requests": []
}]
: {
"name": "",
"requests": []
};
for(let collectionItem of collection.item) {
if (collectionItem.request) {
if (postwomanCollection[0]) {
postwomanCollection[0].name = collection.info ? collection.info.name : "";
postwomanCollection[0].requests.push(this.parsePostmanRequest(collectionItem));
} else {
postwomanCollection.name = collection.name ? collection.name
: "";
postwomanCollection.requests.push(this.parsePostmanRequest(collectionItem));
}
} else if (collectionItem.item) {
if (collectionItem.item[0]) {
postwomanCollection[0].folders.push(this.parsePostmanCollection(collectionItem, false));
}
}
}
return postwomanCollection;
},
parsePostmanRequest(requestObject) {
let pwRequest = {
"url": "",
"path": "",
"method": "",
"auth": "",
"httpUser": "",
"httpPassword": "",
"passwordFieldType": "password",
"bearerToken": "",
"headers": [],
"params": [],
"bodyParams": [],
"rawParams": "",
"rawInput": false,
"contentType": "",
"requestType": "",
"name": "",
};
pwRequest.name = requestObject.name;
let requestObjectUrl = requestObject.request.url.raw.match(/^(.+:\/\/[^\/]+|{[^\/]+})(\/[^\?]+|).*$/);
pwRequest.url = requestObjectUrl[1];
pwRequest.path = requestObjectUrl[2] ? requestObjectUrl[2] : "";
pwRequest.method = requestObject.request.method;
let itemAuth = requestObject.request.auth ? requestObject.request.auth
: "";
let authType = itemAuth ? itemAuth.type
: "";
if (authType === "basic") {
pwRequest.auth = "Basic Auth";
pwRequest.httpUser = itemAuth.basic[0].key === "username"
? itemAuth.basic[0].value
: itemAuth.basic[1].value;
pwRequest.httpPassword = itemAuth.basic[0].key === "password"
? itemAuth.basic[0].value
: itemAuth.basic[1].value;
} else if (authType === "oauth2") {
pwRequest.auth = "OAuth 2.0";
pwRequest.bearerToken = itemAuth.oauth2[0].key === "accessToken"
? itemAuth.oauth2[0].value
: itemAuth.oauth2[1].value;
} else if (authType === "bearer") {
pwRequest.auth = "Bearer Token";
pwRequest.bearerToken = itemAuth.bearer[0].value;
}
let requestObjectHeaders = requestObject.request.header;
if (requestObjectHeaders) {
pwRequest.headers = requestObjectHeaders;
for (let header of pwRequest.headers) {
delete header.name;
delete header.type;
}
}
let requestObjectParams = requestObject.request.url.query;
if (requestObjectParams) {
pwRequest.params = requestObjectParams;
for (let param of pwRequest.params) {
delete param.disabled;
}
}
if (requestObject.request.body) {
if (requestObject.request.body.mode === "urlencoded") {
let params = requestObject.request.body.urlencoded;
pwRequest.bodyParams = params ? params : [];
for(let param of pwRequest.bodyParams) {
delete param.type;
}
} else if (requestObject.request.body.mode === "raw") {
pwRequest.rawInput = true;
pwRequest.rawParams = requestObject.request.body.raw;
}
}
return pwRequest;
}
}
};

View File

@@ -25,7 +25,7 @@
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.87);
background-color: rgba(0, 0, 0, 0.32);
display: flex;
align-items: center;
justify-content: center;

View File

@@ -222,6 +222,7 @@ export default {
payload: "Payload",
choose_file: "Choose a file",
file_imported: "File imported",
import_failed: "Import failed",
f12_details: "(F12 for details)",
we_use_cookies: "We use cookies",
copied_to_clipboard: "Copied to clipboard",

6
package-lock.json generated
View File

@@ -12087,9 +12087,9 @@
"integrity": "sha512-GVbwInwnqkVxQ4GU/XYeQt1e0dAXL8sF5Hr1H/coCBbYUan5xP0G2mEz/HRDf1lt73rFQAN/bJcLTOKkqiM6tg=="
},
"vue-virtual-scroll-list": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/vue-virtual-scroll-list/-/vue-virtual-scroll-list-1.4.4.tgz",
"integrity": "sha512-wU7FDpd9Xy4f62pf8SBg/ak21jMI/pdx4s4JPah+z/zuhmeAafQgp8BjtZvvt+b0BZOsOS1FJuCfUH7azTkivQ=="
"version": "1.4.5",
"resolved": "https://registry.npmjs.org/vue-virtual-scroll-list/-/vue-virtual-scroll-list-1.4.5.tgz",
"integrity": "sha512-9Rdq5acfwHcOmtIJC9LeLdfaXnXuJW6DwyGxXEgIT3aMyXbluP4eEMnKC3uNQ/kiZ0Eno7G95xYfWvopEMQpmA=="
},
"vuefire": {
"version": "2.2.1",

View File

@@ -31,7 +31,7 @@
"nuxt": "^2.11.0",
"nuxt-i18n": "^6.5.0",
"v-tooltip": "^2.0.3",
"vue-virtual-scroll-list": "^1.4.4",
"vue-virtual-scroll-list": "^1.4.5",
"vuefire": "^2.2.1",
"vuejs-auto-complete": "^0.9.0",
"vuex-persist": "^2.2.0",

View File

@@ -247,7 +247,6 @@
<span>
<pw-toggle :on="rawInput" @change="rawInput = $event">
{{ $t("raw_input") }}
{{ rawInput ? $t("enabled") : $t("disabled") }}
</pw-toggle>
</span>
<div>
@@ -459,7 +458,8 @@
:disabled="!isValidURL"
v-tooltip.bottom="$t('copy_request_link')"
>
<i class="material-icons">file_copy</i>
<i v-if="navigatorShare" class="material-icons">share</i>
<i v-else class="material-icons">file_copy</i>
</button>
<button
class="icon"
@@ -1510,7 +1510,8 @@ export default {
fb,
customMethod: false,
files: [],
filenames: ""
filenames: "",
navigatorShare: navigator.share
};
},
watch: {

View File

@@ -270,7 +270,7 @@ export default {
aceEditor: "vibrant_ink"
},
{
color: "var(--bg-color)",
color: "var(--ac-color)",
name: this.$t("auto_system"),
vibrant: window.matchMedia("(prefers-color-scheme: light)").matches,
class: "auto",