Add project files.
This commit is contained in:
80
paperless-ngx-export.service/Program.cs
Normal file
80
paperless-ngx-export.service/Program.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using paperless_ngx_export;
|
||||
using System.IO;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.service
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapGet("/", (IConfiguration config) =>
|
||||
#if DEBUG
|
||||
{
|
||||
return Results.Content("<html><body><a href=\"/calendar\">Calendar</a><br /><a href=\"/spreadsheet\">Spreadsheet</a></body></html>", "text/html");
|
||||
}
|
||||
#else
|
||||
"API"
|
||||
#endif
|
||||
);
|
||||
|
||||
app.MapGet("/calendar", async (IConfiguration config) =>
|
||||
{
|
||||
// Retrieve the environment variable
|
||||
string? apiToken = config["PAPERLESS_TOKEN"];
|
||||
string? apiBase = config["PAPERLESS_API_URI"];
|
||||
|
||||
if (apiToken == null)
|
||||
{
|
||||
return Results.Problem("PAPERLESS_TOKEN is missing from the environment.");
|
||||
}
|
||||
if (apiBase== null)
|
||||
{
|
||||
return Results.Problem("PAPERLESS_API_URI is missing from the environment.");
|
||||
}
|
||||
|
||||
api.init(apiToken!, apiBase!);
|
||||
|
||||
var caldav = await api.getExpirationDatesCalDAVAsync();
|
||||
return Results.Content(caldav, "text/calendar", Encoding.UTF8);
|
||||
});
|
||||
|
||||
app.MapGet("/spreadsheet", async (IConfiguration config) =>
|
||||
{
|
||||
#if DEBUG
|
||||
string? apiToken = "cfa320a52bec92cc7bef74415238ee000fc42a3c";
|
||||
string? apiBase = "https://paperless.camcass.ca/api/";
|
||||
#else
|
||||
// Retrieve the environment variable
|
||||
string? apiToken = config["PAPERLESS_TOKEN"];
|
||||
string? apiBase = config["PAPERLESS_API_URI"];
|
||||
#endif
|
||||
|
||||
if (apiToken == null)
|
||||
{
|
||||
return Results.Problem("PAPERLESS_TOKEN is missing from the environment.");
|
||||
}
|
||||
if (apiBase == null)
|
||||
{
|
||||
return Results.Problem("PAPERLESS_API_URI is missing from the environment.");
|
||||
}
|
||||
|
||||
api.init(apiToken!, apiBase!);
|
||||
|
||||
var content = await spreadsheet.GetSummarySpreadsheetAsByteArrayAsync();
|
||||
|
||||
return Results.File(
|
||||
content,
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"Report.xlsx");
|
||||
});
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user