Added Paperless display POC

This commit is contained in:
Samuel Andert
2023-09-20 20:56:27 +02:00
parent 804a618053
commit 0312f50d51
11 changed files with 145 additions and 54 deletions

View File

@ -1,5 +0,0 @@
query {
cloudron_getProfile {
email
}
}

View File

@ -6,15 +6,15 @@ export default createOperation.query({
address: z.string(),
}),
handler: async ({ input }) => {
console.log('Making request with input:', input); // Log the input
console.log('Making request with input:', input);
const { data } = await axios.get('https://api.gnosisscan.io/api', {
params: {
module: 'account',
action: 'balance',
address: input.address,
// tag: 'latest',
// apikey: process.env.GNOSISSCAN_API,
tag: 'latest',
apikey: process.env.GNOSISSCAN_API,
},
timeout: 10000,
});

View File

@ -0,0 +1,39 @@
// .wundergraph/operations/getPaperless.ts
import { createOperation, z } from '../generated/wundergraph.factory';
import axios from 'axios';
export default createOperation.query({
input: z.object({}),
handler: async () => {
console.log('Making request to Paperless API');
const { data } = await axios.get('https://paperless.andert.me/api/documents/', {
headers: {
Authorization: process.env.PAPERLESS_TOKEN,
},
});
console.log('Received response:', data.results);
// Add download link, thumbnail link, preview link, and PDF data to each document
const documentsWithLinksAndData = await Promise.all(data.results.map(async doc => {
const response = await axios.get(`https://paperless.andert.me/api/documents/${doc.id}/preview/`, {
responseType: 'arraybuffer',
headers: {
Authorization: process.env.PAPERLESS_TOKEN,
},
});
const pdfData = Buffer.from(response.data, 'binary').toString('base64');
return {
...doc,
downloadLink: `https://paperless.andert.me/api/documents/${doc.id}/download/`,
thumbnailLink: `https://paperless.andert.me/api/documents/${doc.id}/thumb/`,
previewLink: `https://paperless.andert.me/api/documents/${doc.id}/preview/`,
pdfData,
};
}));
return documentsWithLinksAndData;
},
});

View File

@ -26,16 +26,6 @@ const placeholder = introspect.openApiV2({
baseURL: 'https://jsonplaceholder.typicode.com',
});
const cloudron = introspect.openApiV2({
apiNamespace: 'cloudron',
source: {
kind: "file",
filePath: "./schemas/cloudron.json"
},
headers: (builder) => builder
.addStaticHeader('Authorization', new EnvironmentVariable('CLOUDRON_API', process.env.CLOUDRON_API))
});
const system_db = introspect.graphql({
apiNamespace: 'system_db',
loadSchemaFromString: directusSystemSchema,
@ -46,7 +36,7 @@ const system_db = introspect.graphql({
// configureWunderGraph emits the configuration
configureWunderGraphApplication({
apis: [db, system_db, placeholder, cloudron],
apis: [db, system_db, placeholder],
server,
operations,
generate: {