Refactor PDF handling and update config

Simplified the return logic in `SwissQrCodeController` by removing conditional checks and directly returning the result.

Refactored `DevExpressPdfProcessor` to handle encrypted PDFs more effectively by checking for encryption before attempting to load with DevExpress, thus avoiding potential errors. Metadata extraction is now limited to non-encrypted PDFs.

Added `opencode.jsonc` configuration file to define schema and specify paths for integrating external AI skills with the OpenCode AI platform.
This commit is contained in:
2026-10-22 01:43:19 +02:00
parent 0db28a025f
commit de5e2d613f
3 changed files with 45 additions and 22 deletions

View File

@@ -55,7 +55,7 @@ public class SwissQrCodeController(IMediator Mediator) : ControllerBase
};
var result = await Mediator.Send(query, cancellationToken);
return Ok(raw ? result.RawLines : result.Bill);
return Ok(result);
}
/// <summary>
@@ -97,7 +97,7 @@ public class SwissQrCodeController(IMediator Mediator) : ControllerBase
var query = new ExtractSwissQrCodeQuery { PdfStream = pdfStream };
var result = await Mediator.Send(query, cancellationToken);
return Ok(raw ? result.RawLines : result.Bill);
return Ok(result);
}
}

View File

@@ -123,23 +123,7 @@ public class DevExpressPdfProcessor : IPdfProcessor
pdfBytes = memoryStream.ToArray();
}
// 3. Load PDF with DevExpress Document API
// Reset position for DevExpress (seekable streams only)
if (pdfStream.CanSeek)
{
pdfStream.Position = 0;
}
using var processor = new PdfDocumentProcessor();
processor.LoadDocument(pdfStream);
var document = processor.Document;
// 4. Extract basic metadata
int pageCount = document.Pages.Count;
string pdfVersion = document.Version.ToString();
// 5. Check encryption (scan PDF raw data for /Encrypt keyword)
// 3. Check encryption (scan PDF raw data for /Encrypt keyword)
bool encrypted = DetectEncryption(pdfBytes);
// 6. Check PDF/A conformance (scan PDF raw data for PDF/A identifier)
@@ -149,13 +133,42 @@ public class DevExpressPdfProcessor : IPdfProcessor
var errors = new List<string>();
var warnings = new List<string>();
// If encrypted, PDF/A compliance is not possible
if (encrypted && isPdfACompliant)
int pageCount = 0;
string pdfVersion = string.Empty;
// If encrypted, skip DevExpress loading (it will throw) and return early
if (encrypted)
{
errors.Add("PDF/A documents cannot be encrypted");
isPdfACompliant = false;
errors.Add("PDF/A documents cannot be encrypted");
return new PdfAValidationResult
{
IsValid = false,
PdfVersion = pdfVersion,
PageCount = pageCount,
FileSize = pdfBytes.Length,
Encrypted = true,
PdfAVersion = null,
PdfACompliant = false,
Errors = errors,
Warnings = warnings
};
}
// Load PDF with DevExpress Document API (only for non-encrypted PDFs)
if (pdfStream.CanSeek)
pdfStream.Position = 0;
using var processor = new PdfDocumentProcessor();
processor.LoadDocument(pdfStream);
var document = processor.Document;
// 4. Extract basic metadata
pageCount = document.Pages.Count;
pdfVersion = document.Version.ToString();
// Basic PDF/A validation checks
if (isPdfACompliant)
{

10
opencode.jsonc Normal file
View File

@@ -0,0 +1,10 @@
{
"$schema": "https://opencode.ai/config.json",
"skills": {
"paths": [
"~/.config/opencode/skills/external/andrej-karpathy-skills/skills",
"~/.config/opencode/skills/external/ponytail/skills",
"~/.config/opencode/skills/external/i-have-adhd/skills"
]
}
}