AttachmentSystem for NAT file processing

This commit is contained in:
2021-09-07 19:53:36 -06:00
parent 7c8a80057f
commit 48b3051c17
3 changed files with 34 additions and 0 deletions

View File

@@ -152,6 +152,9 @@
// Add systems!
(archive.addSystem nameSystem)
(archive.addSystem (new WikipediaImageSystem))
// Just for testing:
(archive.addSystem (new AttachmentSystem ["jpg" "jpeg" "png"] ->[archive e files] ~files))
(archive.processSystems)
(defCommand Help []

View File

@@ -0,0 +1,17 @@
package nat.systems;
import kiss.Prelude;
import kiss.List;
import nat.System;
import haxe.Json;
using haxe.io.Path;
typedef AttachmentProcessor = (Archive, Entry, Array<String>) -> Dynamic;
/**
* Base System that processes Entries based on whether they have file attachments
* which match a given set of extensions
*/
@:build(kiss.Kiss.build())
class AttachmentSystem extends System {}

View File

@@ -0,0 +1,14 @@
(load "../Lib.kiss")
(defNew [&prop :Array<String> extensions
:AttachmentProcessor processor]
(super
->[archive e]
{
(doFor file e.files
(when !(= -1 (extensions.indexOf (file.extension)))
(return true)))
false
}
->[archive e]
(processor archive e (filter e.files ->file !(= -1 (extensions.indexOf (file.extension)))))))