This repository has been archived by the owner on Aug 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from readium/fixes/webpub
Add support for remote Web Publication
- Loading branch information
Showing
4 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// DocumentTypes.swift | ||
// r2-shared-swift | ||
// | ||
// Created by Mickaël Menu on 26.06.19. | ||
// | ||
// Copyright 2019 Readium Foundation. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license which is detailed | ||
// in the LICENSE file present in the project repository where this source code is maintained. | ||
// | ||
|
||
import CoreServices | ||
import Foundation | ||
|
||
public final class DocumentTypes { | ||
|
||
// Extracts supported Document Types from the main bundle's Info.plist. | ||
private static let types = (Bundle.main.object(forInfoDictionaryKey: "CFBundleDocumentTypes") as? [[String: Any]] ?? []) | ||
|
||
/// Supported UTI. | ||
public static let utis: [String] = types | ||
.flatMap { $0["LSItemContentTypes"] as? [String] ?? [] } | ||
|
||
/// Supported document content types. | ||
public static let contentTypes: [String] = utis | ||
.compactMap { UTTypeCopyPreferredTagWithClass($0 as CFString, kUTTagClassMIMEType)?.takeRetainedValue() as String? } | ||
|
||
/// Supported document extensions. | ||
public static let extensions: [String] = types | ||
.flatMap { $0["CFBundleTypeExtensions"] as? [String] ?? [] } | ||
.map { $0.lowercased() } | ||
|
||
/// Returns the content type for the given URL. | ||
public static func contentType(for url: URL?) -> String? { | ||
return contentType(forExtension: url?.pathExtension) | ||
} | ||
|
||
/// Returns the content type for the given document extension. | ||
public static func contentType(forExtension ext: String?) -> String? { | ||
guard let ext = ext else { | ||
return nil | ||
} | ||
return (UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, ext as CFString, nil)?.takeUnretainedValue()) | ||
.flatMap { UTTypeCopyPreferredTagWithClass($0, kUTTagClassMIMEType)?.takeRetainedValue() as String? } | ||
} | ||
|
||
/// Returns the document extension for given content type. | ||
public static func `extension`(forContentType contentType: String?) -> String? { | ||
guard let contentType = contentType else { | ||
return nil | ||
} | ||
return (UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, contentType as CFString, nil)?.takeUnretainedValue()) | ||
.flatMap { UTTypeCopyPreferredTagWithClass($0, kUTTagClassFilenameExtension)?.takeRetainedValue() as String? } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// ResourcesServer.swift | ||
// r2-shared-swift | ||
// | ||
// Created by Mickaël Menu on 21.06.19. | ||
// | ||
// Copyright 2019 Readium Foundation. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license which is detailed | ||
// in the LICENSE file present in the project repository where this source code is maintained. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum ResourcesServerError: Error { | ||
case fileNotFound | ||
case invalidPath | ||
case serverFailure | ||
} | ||
|
||
public protocol ResourcesServer { | ||
|
||
/// Serves the local file URL at the given absolute path on the server. | ||
/// If the given URL is a directory, then all the files in the directory are served. | ||
/// Subsequent calls with the same served path overwrite each other. | ||
/// | ||
/// Returns: The URL to access the file on the server. | ||
@discardableResult | ||
func serve(_ url: URL, at path: String) throws -> URL | ||
|
||
} |