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
|
// IMAP CLIENT INITIALIZEN
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
export async function initDokuboxClient() {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
// MAIN SYNC FUNCTION (DRIZZLE VERSION)
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
|
export function syncDokuboxService (server: FastifyInstance) {
|
||||||
|
async function initDokuboxClient() {
|
||||||
client = new ImapFlow({
|
client = new ImapFlow({
|
||||||
host: secrets.DOKUBOX_IMAP_HOST,
|
host: secrets.DOKUBOX_IMAP_HOST,
|
||||||
port: secrets.DOKUBOX_IMAP_PORT,
|
port: secrets.DOKUBOX_IMAP_PORT,
|
||||||
@@ -44,13 +53,7 @@ export async function initDokuboxClient() {
|
|||||||
await client.connect()
|
await client.connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const syncDokubox = async () => {
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
|
||||||
// MAIN SYNC FUNCTION (DRIZZLE VERSION)
|
|
||||||
// -------------------------------------------------------------
|
|
||||||
export const syncDokubox = (server: FastifyInstance) =>
|
|
||||||
async () => {
|
|
||||||
|
|
||||||
console.log("Perform Dokubox Sync")
|
console.log("Perform Dokubox Sync")
|
||||||
|
|
||||||
@@ -130,11 +133,6 @@ export const syncDokubox = (server: FastifyInstance) =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
|
||||||
// TENANT ERKENNEN + FOLDER/FILETYPES (DRIZZLE VERSION)
|
|
||||||
// -------------------------------------------------------------
|
|
||||||
const getMessageConfigDrizzle = async (
|
const getMessageConfigDrizzle = async (
|
||||||
server: FastifyInstance,
|
server: FastifyInstance,
|
||||||
message,
|
message,
|
||||||
@@ -257,3 +255,21 @@ const getMessageConfigDrizzle = async (
|
|||||||
filetype: filetypeId
|
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
|
// /plugins/services.ts
|
||||||
import fp from "fastify-plugin";
|
import fp from "fastify-plugin";
|
||||||
import { bankStatementService } from "../modules/cron/bankstatementsync.service";
|
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 { FastifyInstance } from "fastify";
|
||||||
import {prepareIncomingInvoices} from "../modules/cron/prepareIncomingInvoices";
|
import {prepareIncomingInvoices} from "../modules/cron/prepareIncomingInvoices";
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ declare module "fastify" {
|
|||||||
interface FastifyInstance {
|
interface FastifyInstance {
|
||||||
services: {
|
services: {
|
||||||
bankStatements: ReturnType<typeof bankStatementService>;
|
bankStatements: ReturnType<typeof bankStatementService>;
|
||||||
//dokuboxSync: ReturnType<typeof syncDokubox>;
|
dokuboxSync: ReturnType<typeof syncDokuboxService>;
|
||||||
prepareIncomingInvoices: ReturnType<typeof prepareIncomingInvoices>;
|
prepareIncomingInvoices: ReturnType<typeof prepareIncomingInvoices>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ declare module "fastify" {
|
|||||||
export default fp(async function servicePlugin(server: FastifyInstance) {
|
export default fp(async function servicePlugin(server: FastifyInstance) {
|
||||||
server.decorate("services", {
|
server.decorate("services", {
|
||||||
bankStatements: bankStatementService(server),
|
bankStatements: bankStatementService(server),
|
||||||
//dokuboxSync: syncDokubox(server),
|
dokuboxSync: syncDokuboxService(server),
|
||||||
prepareIncomingInvoices: prepareIncomingInvoices(server),
|
prepareIncomingInvoices: prepareIncomingInvoices(server),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -179,6 +179,11 @@ export default async function functionRoutes(server: FastifyInstance) {
|
|||||||
await server.services.prepareIncomingInvoices.run(req.user.tenant_id)
|
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) => {
|
/*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}
|
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 route = useRoute()
|
||||||
const modal = useModal()
|
const modal = useModal()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
const { $api } = useNuxtApp()
|
||||||
const files = useFiles()
|
const files = useFiles()
|
||||||
|
|
||||||
// --- State ---
|
// --- State ---
|
||||||
@@ -222,11 +223,50 @@ defineShortcuts({
|
|||||||
'arrowdown': () => { if (selectedFileIndex.value < renderedFileList.value.length - 1) selectedFileIndex.value++ },
|
'arrowdown': () => { if (selectedFileIndex.value < renderedFileList.value.length - 1) selectedFileIndex.value++ },
|
||||||
'arrowup': () => { if (selectedFileIndex.value > 0) 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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<UDashboardNavbar title="Dateien">
|
<UDashboardNavbar title="Dateien">
|
||||||
<template #right>
|
<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" />
|
<UInput id="searchinput" v-model="searchString" icon="i-heroicons-magnifying-glass" placeholder="Suche..." class="w-64" />
|
||||||
</template>
|
</template>
|
||||||
</UDashboardNavbar>
|
</UDashboardNavbar>
|
||||||
|
|||||||
Reference in New Issue
Block a user