Other Functions
The following functions are available globally.
-
Declaration
Swift
func generateSchedule(startDate: Date, length: Int) -
Declaration
Swift
func printEvent(date: Date, startTime: String, endTime: String, summary: String, description: String, location: String, categories: String, uid: String)
-
QuartermasterCreateDataandQuartermasterContentDataboth carry an optionallocationfield with the same bounds; this fn exists to ensure they validate it the same way. Returns a list of validation failure strings–if it returns an empty array the location is valid (or absent, which is allowed).Declaration
Swift
private func quartermasterLocationValidations(location: String?) -> [String] -
QuartermasterCreateDataandQuartermasterContentDataboth requirelocationto be present whenhideOwnerNameistrue, since it becomes the only way for other users to identify the item; this fn exists to ensure they enforce that the same way.Declaration
Swift
private func validateQuartermasterLocationRequiredIfHidden(location: String?, hideOwnerName: Bool) throws
-
Three differernt POST structs contain username fields; this fn exists to ensure they all validate the username the same way. This fn is designed to return a list of validation failure strings–if it returns an empty array the username is valid.
Declaration
Swift
private func usernameValidations(username: String) -> [String] -
Parses an ISO 8601 internet date-time, with or without fractional seconds. Swiftarr always emits fractional seconds but accepts timestamps that omit them.
Declaration
Swift
@available(macOS 10.13, *) private func dateFromISO8601(_ string: String) -> Date? -
logNotification(type:Asynchronousinfo: recipients: db: logger: ) Writes a durable log entry for a notification event that’s about to be (or was just) pushed to live sockets–see
GET /api/v3/notification/log. OneNotificationLogEntryrow is created for the event itself, plus oneNotificationRecipientrow per user inrecipients, so a broadcast notification sent to many users doesn’t duplicate its content once per recipient.The log is a convenience history, not the source of truth for notification delivery, so a failure here is logged and swallowed rather than thrown–it should never prevent the actual notification from going out.
Declaration
Swift
func logNotification(type: NotificationType, info: String, recipients: [UUID], db: Database, logger: Logger) async -> UUID?Return Value
The new entry’s ID (to be included in the live socket push as
notificationID), or nil if there were no recipients or the write failed. -
Returns the file system path for the given image filename. Makes sure all image directories in the path exist.
Currently, this fn returns paths in the form:
/images/ / / .jpg where “xx” is the first 2 characters of the filename. Declaration
Swift
func getImagePath(for image: String, format: String? = nil, usage: ImageUsage, size: ImageSizeGroup) throws -> URL -
Returns true when the image data is a format that can carry animation (GIF or WebP).
Declaration
Swift
func isAnimatableFormat(_ data: Data) -> Bool -
Detects the file extension for image data. Returns “jpg” for unrecognized formats.
Declaration
Swift
func detectExtension(_ data: Data) -> String -
Loads an image from data, auto-detecting format and applying EXIF rotation. Alpha is preserved — flattening only happens at JPEG export sites, since PNG/GIF/WebP outputs can carry transparency.
Declaration
Swift
func loadImageFromData(_ data: Data) throws -> SwiftarrImageParameters
dataThe image data to load
Return Value
The loaded image, ready for processing
-
Resizes an image to thumbnail size and encodes it in the requested format. Returns nil if resize fails. JPEG output flattens any alpha onto a white background; PNG/GIF/WebP outputs preserve transparency.
Declaration
Swift
func thumbnailData(from image: SwiftarrImage, format: String) throws -> Data? -
Creates a thumbnail from an image and writes it to disk in the specified format. Silently skips thumbnail creation if resize fails, matching the original behavior.
Throws
Errors from export or file write operationsDeclaration
Swift
func createThumbnail(from image: SwiftarrImage, to thumbPath: URL, format: String, logger: Logger) throwsParameters
imageThe source image to create a thumbnail from
thumbPathThe file path where the thumbnail should be saved
formatThe output format extension (“jpg”, “png”, etc.)
loggerUsed to report a failed resize
-
Validates, processes and stores one image: full-size and thumbnail versions, in the image store. Returns the stored filename.
This is the single place image processing happens, shared by uploads (
processImage) and anything that needs to store an image without aRequest, such as migrations that seed records with images. The format is detected from the data’s contents, not any filename. PNG/GIF/WebP are kept in their own format when unmodified; everything else (JPEG, HEIC, AVIF, …) and anything we had to resize or crop is re-encoded as a JPEG, so the stored bytes always match the stored filename’s extension.This is synchronous and does blocking file and image work, so request handlers should call it from a thread pool.
Declaration
Swift
func processImageData(_ data: Data, usage: ImageUsage, logger: Logger) throws -> String
-
Declaration
Swift
func generateContentGroups(from reports: [ReportModerationData]) -> [ReportContentGroup] -
Declaration
Swift
private func titleAndTab(for req: Request) -> (String, TrunkContext.Tab) -
Declaration
Swift
private func titleAndTab(for req: Request, seamail: FezData) -> (String, TrunkContext.Tab) -
Register your application’s routes here.
Declaration
Swift
public func routes(_ app: Application) throws
View on GitHub
Other Functions Reference