-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
807 additions
and
257 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
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,29 @@ | ||
// | ||
// UrlPreviewerModel.swift | ||
// MissCat | ||
// | ||
// Created by Yuiga Wada on 2020/04/07. | ||
// Copyright © 2020 Yuiga Wada. All rights reserved. | ||
// | ||
|
||
import SwiftLinkPreview | ||
|
||
class UrlPreviewerModel { | ||
func getPreview(of url: String, handler: @escaping (Response) -> Void) { | ||
if let cache = Cache.shared.getUrlPreview(on: url) { | ||
DispatchQueue.main.async { handler(cache) } | ||
return | ||
} | ||
|
||
let slp = SwiftLinkPreview(session: URLSession.shared, | ||
workQueue: DispatchQueue.global(), | ||
responseQueue: DispatchQueue.main) | ||
|
||
slp.preview(url, onSuccess: { res in | ||
Cache.shared.saveUrlPreview(response: res, on: url) | ||
handler(res) | ||
}, onError: handleError) | ||
} | ||
|
||
private func handleError(_ error: PreviewError) {} | ||
} |
Oops, something went wrong.