57 lines
1.2 KiB
Markdown
57 lines
1.2 KiB
Markdown
```swift title="Swift"
|
|
import Kreuzberg
|
|
import os.log
|
|
|
|
let logger = Logger(subsystem: "com.example.plugins", category: "MyPlugin")
|
|
|
|
final class MyPlugin: PostProcessor {
|
|
func name() -> String {
|
|
"my-plugin"
|
|
}
|
|
|
|
func version() -> String {
|
|
"1.0.0"
|
|
}
|
|
|
|
func initialize() -> String {
|
|
logger.info("Initializing plugin: my-plugin")
|
|
return "{\"ok\": null}"
|
|
}
|
|
|
|
func shutdown() -> String {
|
|
logger.info("Shutting down plugin: my-plugin")
|
|
return "{\"ok\": null}"
|
|
}
|
|
|
|
func process(result: ExtractionResult, config: ExtractionConfig) -> String {
|
|
let contentLen = result.content().count
|
|
logger.info("Processing \(result.mimeType()) (\(contentLen) bytes)")
|
|
|
|
if contentLen == 0 {
|
|
logger.warning("Processing resulted in empty content")
|
|
}
|
|
|
|
return "{\"ok\": null}"
|
|
}
|
|
|
|
func shouldProcess(result: ExtractionResult, config: ExtractionConfig) -> Bool {
|
|
true
|
|
}
|
|
|
|
func processingStage() -> String {
|
|
"early"
|
|
}
|
|
|
|
func priority() -> Int32 {
|
|
50
|
|
}
|
|
|
|
func estimatedDurationMs(result: ExtractionResult) -> UInt64 {
|
|
10
|
|
}
|
|
}
|
|
|
|
let plugin = MyPlugin()
|
|
try Kreuzberg.registerPostProcessor(plugin)
|
|
```
|