Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Import from file
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jul 14, 2022
1 parent 5371825 commit f7177cc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
15 changes: 11 additions & 4 deletions interface/windows/codes/codes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</svg>
Import codes
</button>
<button class="button">
<button class="button" on:click={chooseImportFile}>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M10 21h7a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v11m0 5l4.879-4.879m0 0a3 3 0 104.243-4.242 3 3 0 00-4.243 4.242z" />
</svg>
Expand Down Expand Up @@ -102,10 +102,17 @@

<script lang="ts">
import { onMount, onDestroy } from "svelte"
import { test, stopCodesRefresher, search } from "./index"
import { textConverter } from "../../../libraries/convert"
import { stopCodesRefresher, search, chooseImportFile, generateCodeElements } from "./index"
import { navigate } from "../../../libraries/navigate"
import { state } from "../../stores/state"
onMount(() => {
test()
const stateSubscriber = state.subscribe((data) => {
if (data.importData !== null) {
onMount(() => {
generateCodeElements(textConverter(data.importData, 0))
})
}
})
onDestroy(() => {
Expand Down
33 changes: 14 additions & 19 deletions interface/windows/codes/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
import { textConverter } from "../../../libraries/convert"
import { TOTP } from "otpauth"
import { dialog, fs } from "@tauri-apps/api"

let codesRefresher: NodeJS.Timer
const searchQuery: string[] = []

export const test = () => {
const text = `
Name: Google:leventelorik92@gmail.com
Secret: BVPK3JHAZO5AF6XUYS6AYMB3Y5KDR6R2
Issuer: Google
Type: OTP_TOTP
Name: Levminer@leventelorik92@gmail.com
Secret: HVV3CUZC6RRGFK5L
Issuer: GitHub
Type: OTP_TOTP `

let arr = textConverter(text, 0)

console.log(arr)

generateCodeElements(arr)
}

export const generateCodeElements = (data: LibImportFile) => {
const names = data.names
const secrets = data.secrets
Expand Down Expand Up @@ -190,3 +172,16 @@ export const search = () => {
document.querySelector(".searchResult").textContent = input
}
}

export const chooseImportFile = async () => {
const filePath = await dialog.open({ filters: [{ name: "Authme file", extensions: ["authme"] }] })

if (filePath !== null) {
const loadedFile = await fs.readTextFile(filePath.toString())
const file: LibAuthmeFile = JSON.parse(loadedFile)

const codes = textConverter(Buffer.from(file.codes, "base64").toString(), 0)

generateCodeElements(codes)
}
}

0 comments on commit f7177cc

Please sign in to comment.