Browse Source

Add importing of 1passwords 1pux files (#440)

* Pull in jslib

* Install jszip

* Add method in utils to unzip and extract 1pux file

* Add importing/extracting of 1pux files to import command

* Update jslib

* Update package-lock.json
pull/2722/head^2
Daniel James Smith 4 years ago committed by GitHub
parent
commit
caf6a1173b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      jslib
  2. 598
      package-lock.json
  3. 1
      package.json
  4. 8
      src/commands/import.command.ts
  5. 17
      src/utils.ts

2
jslib

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit e47eb5e74fd8ff5537149ca033fb395bb0f6295b
Subproject commit 4c408f05242bb0ae00c6c6b7330f1c07a92bdf13

598
package-lock.json generated

File diff suppressed because it is too large Load Diff

1
package.json

@ -106,6 +106,7 @@ @@ -106,6 +106,7 @@
"https-proxy-agent": "5.0.0",
"inquirer": "8.0.0",
"jsdom": "^16.5.3",
"jszip": "^3.7.1",
"koa": "^2.13.4",
"koa-bodyparser": "^4.3.0",
"koa-json": "^2.0.2",

8
src/commands/import.command.ts

@ -61,7 +61,13 @@ export class ImportCommand { @@ -61,7 +61,13 @@ export class ImportCommand {
}
try {
const contents = await CliUtils.readFile(filepath);
let contents;
if (format === "1password1pux") {
contents = await CliUtils.extract1PuxContent(filepath);
} else {
contents = await CliUtils.readFile(filepath);
}
if (contents === null || contents === "") {
return Response.badRequest("Import file was empty.");
}

17
src/utils.ts

@ -3,6 +3,8 @@ import * as fs from "fs"; @@ -3,6 +3,8 @@ import * as fs from "fs";
import * as inquirer from "inquirer";
import * as path from "path";
import * as JSZip from "jszip";
import { Response } from "jslib-node/cli/models/response";
import { MessageResponse } from "jslib-node/cli/models/response/messageResponse";
@ -48,6 +50,21 @@ export class CliUtils { @@ -48,6 +50,21 @@ export class CliUtils {
});
}
static extract1PuxContent(input: string): Promise<string> {
return new JSZip()
.loadAsync(input)
.then((zip) => {
return zip.file("export.data").async("string");
})
.then(
function success(content) {
return content;
},
function error(e) {
return "";
}
);
}
/**
* Save the given data to a file and determine the target file if necessary.
* If output is non-empty, it is used as target filename. Otherwise the target filename is

Loading…
Cancel
Save