|
|
@ -39,6 +39,10 @@ import Camera from "simple-vue-camera"; |
|
|
|
import { Component, Vue } from "vue-facing-decorator"; |
|
|
|
|
|
|
|
import { DEFAULT_IMAGE_API_SERVER } from "@/constants/app"; |
|
|
|
import { getIdentity } from "@/libs/util"; |
|
|
|
import { db } from "@/db/index"; |
|
|
|
import { MASTER_SETTINGS_KEY, Settings } from "@/db/tables/settings"; |
|
|
|
import { accessToken } from "@/libs/crypto"; |
|
|
|
|
|
|
|
interface Notification { |
|
|
|
group: string; |
|
|
@ -51,8 +55,29 @@ interface Notification { |
|
|
|
export default class GiftedPhoto extends Vue { |
|
|
|
$notify!: (notification: Notification, timeout?: number) => void; |
|
|
|
|
|
|
|
activeDid = ""; |
|
|
|
localImageUrl: string | null = null; |
|
|
|
|
|
|
|
async mounted() { |
|
|
|
try { |
|
|
|
await db.open(); |
|
|
|
const settings = (await db.settings.get(MASTER_SETTINGS_KEY)) as Settings; |
|
|
|
this.activeDid = settings?.activeDid || ""; |
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
|
|
|
} catch (err: any) { |
|
|
|
console.error("Error retrieving settings from database:", err); |
|
|
|
this.$notify( |
|
|
|
{ |
|
|
|
group: "alert", |
|
|
|
type: "danger", |
|
|
|
title: "Error", |
|
|
|
text: err.message || "There was an error retrieving your settings.", |
|
|
|
}, |
|
|
|
-1, |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async storeImage(/* payload: MouseEvent */) { |
|
|
|
const cameraComponent = this.$refs.camera as InstanceType<typeof Camera>; |
|
|
|
const blob = await cameraComponent?.snapshot(); |
|
|
@ -69,12 +94,18 @@ export default class GiftedPhoto extends Vue { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const identifier = await getIdentity(this.activeDid); |
|
|
|
const token = await accessToken(identifier); |
|
|
|
const headers = { |
|
|
|
Authorization: "Bearer " + token, |
|
|
|
}; |
|
|
|
const formData = new FormData(); |
|
|
|
formData.append("image", blob, "snapshot.jpg"); |
|
|
|
try { |
|
|
|
const response = await axios.post( |
|
|
|
DEFAULT_IMAGE_API_SERVER + "/image", |
|
|
|
formData, |
|
|
|
{ headers }, |
|
|
|
); |
|
|
|
|
|
|
|
console.log("Sent. Response:", response.data); |
|
|
|