Added Dokubox Sync Service and Button Fix #12
This commit is contained in:
@@ -27,7 +27,16 @@ let client: ImapFlow | null = null
|
||||
// -------------------------------------------------------------
|
||||
// IMAP CLIENT INITIALIZEN
|
||||
// -------------------------------------------------------------
|
||||
export async function initDokuboxClient() {
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// MAIN SYNC FUNCTION (DRIZZLE VERSION)
|
||||
// -------------------------------------------------------------
|
||||
|
||||
export function syncDokuboxService (server: FastifyInstance) {
|
||||
async function initDokuboxClient() {
|
||||
client = new ImapFlow({
|
||||
host: secrets.DOKUBOX_IMAP_HOST,
|
||||
port: secrets.DOKUBOX_IMAP_PORT,
|
||||
@@ -42,15 +51,9 @@ export async function initDokuboxClient() {
|
||||
console.log("Dokubox E-Mail Client Initialized")
|
||||
|
||||
await client.connect()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// MAIN SYNC FUNCTION (DRIZZLE VERSION)
|
||||
// -------------------------------------------------------------
|
||||
export const syncDokubox = (server: FastifyInstance) =>
|
||||
async () => {
|
||||
const syncDokubox = async () => {
|
||||
|
||||
console.log("Perform Dokubox Sync")
|
||||
|
||||
@@ -130,16 +133,11 @@ export const syncDokubox = (server: FastifyInstance) =>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// TENANT ERKENNEN + FOLDER/FILETYPES (DRIZZLE VERSION)
|
||||
// -------------------------------------------------------------
|
||||
const getMessageConfigDrizzle = async (
|
||||
const getMessageConfigDrizzle = async (
|
||||
server: FastifyInstance,
|
||||
message,
|
||||
tenantsList: any[]
|
||||
) => {
|
||||
) => {
|
||||
|
||||
let possibleKeys: string[] = []
|
||||
|
||||
@@ -256,4 +254,22 @@ const getMessageConfigDrizzle = async (
|
||||
folder: folderId,
|
||||
filetype: filetypeId
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
run: async () => {
|
||||
await initDokuboxClient()
|
||||
await syncDokubox()
|
||||
console.log("Service: Dokubox sync finished")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// TENANT ERKENNEN + FOLDER/FILETYPES (DRIZZLE VERSION)
|
||||
// -------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// /plugins/services.ts
|
||||
import fp from "fastify-plugin";
|
||||
import { bankStatementService } from "../modules/cron/bankstatementsync.service";
|
||||
//import {initDokuboxClient, syncDokubox} from "../modules/cron/dokuboximport.service";
|
||||
import {syncDokuboxService} from "../modules/cron/dokuboximport.service";
|
||||
import { FastifyInstance } from "fastify";
|
||||
import {prepareIncomingInvoices} from "../modules/cron/prepareIncomingInvoices";
|
||||
|
||||
@@ -9,7 +9,7 @@ declare module "fastify" {
|
||||
interface FastifyInstance {
|
||||
services: {
|
||||
bankStatements: ReturnType<typeof bankStatementService>;
|
||||
//dokuboxSync: ReturnType<typeof syncDokubox>;
|
||||
dokuboxSync: ReturnType<typeof syncDokuboxService>;
|
||||
prepareIncomingInvoices: ReturnType<typeof prepareIncomingInvoices>;
|
||||
};
|
||||
}
|
||||
@@ -18,7 +18,7 @@ declare module "fastify" {
|
||||
export default fp(async function servicePlugin(server: FastifyInstance) {
|
||||
server.decorate("services", {
|
||||
bankStatements: bankStatementService(server),
|
||||
//dokuboxSync: syncDokubox(server),
|
||||
dokuboxSync: syncDokuboxService(server),
|
||||
prepareIncomingInvoices: prepareIncomingInvoices(server),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -179,6 +179,11 @@ export default async function functionRoutes(server: FastifyInstance) {
|
||||
await server.services.prepareIncomingInvoices.run(req.user.tenant_id)
|
||||
})
|
||||
|
||||
server.post('/functions/services/syncdokubox', async (req, reply) => {
|
||||
|
||||
await server.services.dokuboxSync.run()
|
||||
})
|
||||
|
||||
|
||||
/*server.post('/print/zpl/preview', async (req, reply) => {
|
||||
const { zpl, widthMm = 50, heightMm = 30, dpmm = 8, asBase64 = false } = req.body as {zpl:string,widthMm:number,heightMm:number,dpmm:number,asBase64:string}
|
||||
|
||||
@@ -11,6 +11,7 @@ const router = useRouter()
|
||||
const route = useRoute()
|
||||
const modal = useModal()
|
||||
const toast = useToast()
|
||||
const { $api } = useNuxtApp()
|
||||
const files = useFiles()
|
||||
|
||||
// --- State ---
|
||||
@@ -222,11 +223,50 @@ defineShortcuts({
|
||||
'arrowdown': () => { if (selectedFileIndex.value < renderedFileList.value.length - 1) selectedFileIndex.value++ },
|
||||
'arrowup': () => { if (selectedFileIndex.value > 0) selectedFileIndex.value-- }
|
||||
})
|
||||
|
||||
const isSyncing = ref(false)
|
||||
|
||||
const syncdokubox = async () => {
|
||||
isSyncing.value = true
|
||||
try {
|
||||
await $api('/api/functions/services/syncdokubox', { method: 'POST' })
|
||||
|
||||
toast.add({
|
||||
title: 'Erfolg',
|
||||
description: 'Dokubox wurde synchronisiert.',
|
||||
icon: 'i-heroicons-check-circle',
|
||||
color: 'green'
|
||||
})
|
||||
|
||||
// Liste neu laden
|
||||
await setupPage()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.add({
|
||||
title: 'Fehler',
|
||||
description: 'Beim Synchronisieren der Dokubox ist ein Fehler aufgetreten.',
|
||||
icon: 'i-heroicons-exclamation-circle',
|
||||
color: 'red'
|
||||
})
|
||||
} finally {
|
||||
isSyncing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UDashboardNavbar title="Dateien">
|
||||
<template #right>
|
||||
<UButton
|
||||
label="Dokubox Sync"
|
||||
icon="i-heroicons-sparkles"
|
||||
color="primary"
|
||||
variant="solid"
|
||||
:loading="isSyncing"
|
||||
@click="syncdokubox"
|
||||
class="mr-2"
|
||||
/>
|
||||
<UInput id="searchinput" v-model="searchString" icon="i-heroicons-magnifying-glass" placeholder="Suche..." class="w-64" />
|
||||
</template>
|
||||
</UDashboardNavbar>
|
||||
|
||||
Reference in New Issue
Block a user