Firebase sync

This commit is contained in:
Liyas Thomas
2020-02-24 00:30:22 +05:30
parent 010be95ed5
commit d24c572d7f
8 changed files with 164 additions and 76 deletions

View File

@@ -121,12 +121,19 @@ export default {
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') {
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 if (
collections.info &&
collections.info.schema.includes("v2.1.0")
) {
collections = this.parsePostmanCollection(collections);
} else {
return this.failedImport();
}
@@ -141,11 +148,18 @@ export default {
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') {
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')) {
} else if (
collections.info &&
collections.info.schema.includes("v2.1.0")
) {
collections = this.parsePostmanCollection(collections);
} else {
return this.failedImport();
@@ -188,28 +202,38 @@ export default {
});
},
parsePostmanCollection(collection, folders = true) {
let postwomanCollection = folders ? [{
"name": "",
"folders": [],
"requests": []
}]
let postwomanCollection = folders
? [
{
name: "",
folders: [],
requests: []
}
]
: {
"name": "",
"requests": []
};
for(let collectionItem of collection.item) {
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));
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));
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));
postwomanCollection[0].folders.push(
this.parsePostmanCollection(collectionItem, false)
);
}
}
}
@@ -217,46 +241,51 @@ export default {
},
parsePostmanRequest(requestObject) {
let pwRequest = {
"url": "",
"path": "",
"method": "",
"auth": "",
"httpUser": "",
"httpPassword": "",
"passwordFieldType": "password",
"bearerToken": "",
"headers": [],
"params": [],
"bodyParams": [],
"rawParams": "",
"rawInput": false,
"contentType": "",
"requestType": "",
"name": "",
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(/^(.+:\/\/[^\/]+|{[^\/]+})(\/[^\?]+|).*$/);
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
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;
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;
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;
@@ -280,7 +309,7 @@ export default {
if (requestObject.request.body.mode === "urlencoded") {
let params = requestObject.request.body.urlencoded;
pwRequest.bodyParams = params ? params : [];
for(let param of pwRequest.bodyParams) {
for (let param of pwRequest.bodyParams) {
delete param.type;
}
} else if (requestObject.request.body.mode === "raw") {

View File

@@ -43,6 +43,8 @@
</template>
<script>
import { fb } from "../../functions/fb";
export default {
props: {
show: Boolean
@@ -56,6 +58,15 @@ export default {
};
},
methods: {
syncEnvironments() {
if (fb.currentUser !== null) {
if (fb.currentSettings[1].value) {
fb.writeEnvironments(
JSON.parse(JSON.stringify(this.$store.state.postwoman.environments))
);
}
}
},
addNewEnvironment() {
if (!this.$data.name) {
this.$toast.info($t("invalid_environment_name"));
@@ -69,6 +80,7 @@ export default {
];
this.$store.commit("postwoman/importAddEnvironments", newEnvironment);
this.$emit("hide-modal");
this.syncEnvironments();
},
hideModal() {
this.$emit("hide-modal");

View File

@@ -12,10 +12,6 @@
</div>
</div>
<div class="flex-wrap">
<!-- TODO db syncing
button needs to be switchded to
:disabled=="!fb.currentUser"
-->
<span
v-tooltip="{
content: !fb.currentUser
@@ -23,7 +19,11 @@
: $t('replace_current')
}"
>
<button :disabled="true" class="icon" @click="syncEnvironments">
<button
:disabled="!fb.currentUser"
class="icon"
@click="syncEnvironments"
>
<i class="material-icons">folder_shared</i>
<span>{{ $t("import_from_sync") }}</span>
</button>
@@ -154,7 +154,11 @@ export default {
});
},
syncEnvironments() {
// TODO
this.$store.commit(
"postwoman/replaceEnvironments",
fb.currentEnvironments
);
this.fileImported();
},
fileImported() {
this.$toast.info(this.$t("file_imported"), {

View File

@@ -71,7 +71,7 @@ ul {
<script>
import environment from "./environment";
// import { fb } from "../functions/fb";
import { fb } from "../../functions/fb";
const updateOnLocalStorage = (propertyName, property) =>
window.localStorage.setItem(propertyName, JSON.stringify(property));
@@ -124,17 +124,24 @@ export default {
this.$data.editingEnvironment = environment;
this.$data.editingEnvironmentIndex = environmentIndex;
this.displayModalEdit(true);
this.syncEnvironments;
},
resetSelectedData() {
this.$data.editingEnvironment = undefined;
this.$data.editingEnvironmentIndex = undefined;
},
syncEnvironments() {
// TODO
},
beforeDestroy() {
document.removeEventListener("keydown", this._keyListener);
if (fb.currentUser !== null) {
if (fb.currentSettings[1].value) {
fb.writeEnvironments(
JSON.parse(JSON.stringify(this.$store.state.postwoman.environments))
);
}
}
}
},
beforeDestroy() {
document.removeEventListener("keydown", this._keyListener);
}
};
</script>