Bump version, attempt to refetch PDFs if download signed URL has expired
This commit is contained in:
@ -96,7 +96,18 @@ final class PDFViewerViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
return try await dataService.loadPDFData(slug: pdfItem.slug, downloadURL: pdfItem.downloadURL)
|
||||
if let result = try? await dataService.loadPDFData(slug: pdfItem.slug, downloadURL: pdfItem.downloadURL) {
|
||||
return result
|
||||
}
|
||||
|
||||
// Downloading failed, try to get the article again, and then download
|
||||
if let content = try? await dataService.loadArticleContentWithRetries(itemID: pdfItem.itemID, username: "me") {
|
||||
// refetched the content, now try one more time then throw
|
||||
if let result = try await dataService.loadPDFData(slug: pdfItem.slug, downloadURL: content.downloadURL) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
return nil
|
||||
} catch {
|
||||
print("error downloading PDF", error)
|
||||
return nil
|
||||
|
||||
@ -16,19 +16,22 @@ public struct ArticleContent {
|
||||
public let highlightsJSONString: String
|
||||
public let contentStatus: ArticleContentStatus
|
||||
public let objectID: NSManagedObjectID?
|
||||
public let downloadURL: String
|
||||
|
||||
public init(
|
||||
title: String,
|
||||
htmlContent: String,
|
||||
highlightsJSONString: String,
|
||||
contentStatus: ArticleContentStatus,
|
||||
objectID: NSManagedObjectID?
|
||||
objectID: NSManagedObjectID?,
|
||||
downloadURL: String
|
||||
) {
|
||||
self.title = title
|
||||
self.htmlContent = htmlContent
|
||||
self.highlightsJSONString = highlightsJSONString
|
||||
self.contentStatus = contentStatus
|
||||
self.objectID = objectID
|
||||
self.downloadURL = downloadURL
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -63,7 +63,8 @@ extension DataService {
|
||||
htmlContent: fetchResult.htmlContent,
|
||||
highlightsJSONString: fetchResult.highlights.asJSONString,
|
||||
contentStatus: fetchResult.item.isPDF ? .succeeded : fetchResult.item.state,
|
||||
objectID: objectID
|
||||
objectID: objectID,
|
||||
downloadURL: fetchResult.item.downloadURL
|
||||
)
|
||||
}
|
||||
|
||||
@ -91,7 +92,8 @@ extension DataService {
|
||||
.filter { $0.serverSyncStatus != ServerSyncStatus.needsDeletion.rawValue }
|
||||
.map { InternalHighlight.make(from: $0) }.asJSONString,
|
||||
contentStatus: .succeeded,
|
||||
objectID: linkedItem.objectID
|
||||
objectID: linkedItem.objectID,
|
||||
downloadURL: linkedItem.downloadURL ?? ""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ import { sentryConfig } from './sentry'
|
||||
import { getClaimsByToken, getTokenByRequest } from './utils/auth'
|
||||
import { corsConfig } from './utils/corsConfig'
|
||||
import { buildLogger, buildLoggerTransport } from './utils/logger'
|
||||
import { FirefishClient, createFirefishUserClient } from './activitypub'
|
||||
|
||||
const PORT = process.env.PORT || 4000
|
||||
|
||||
@ -178,4 +179,28 @@ const main = async (): Promise<void> => {
|
||||
// only call main if the file was called from the CLI and wasn't required from another module
|
||||
if (require.main === module) {
|
||||
main()
|
||||
;(async () => {
|
||||
// console.log(
|
||||
// 'creating user with firefish token: ',
|
||||
// process.env.FIREFISH_TOKEN
|
||||
// )
|
||||
// const client = new FirefishClient(
|
||||
// 'http://localhost:8000/api',
|
||||
// process.env.FIREFISH_TOKEN || 'firefish-token',
|
||||
// 'abc123'
|
||||
// )
|
||||
// // const token = await client.createUserActor(
|
||||
// // 'a03a7396-909b-11ed-9075-c3f3cf07eed9',
|
||||
// // 'jacksonh@gmail.com',
|
||||
// // 'jacksonharper'
|
||||
// // )
|
||||
// // console.log('user token: ', token)
|
||||
// // if (token) {
|
||||
// // const secret = client.createAppForActor(token)
|
||||
// // console.log('created secretL: ', secret)
|
||||
// // }
|
||||
// const appClient = createFirefishUserClient('UEpw5pStVG5hFhrX')
|
||||
// appClient.setupUserActor('a03a7396-909b-11ed-9075-c3f3cf07eed9')
|
||||
// appClient.getUserInfo()
|
||||
})()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user