Skip to content

Commit b1a336f

Browse files
committed
refactor(s3): improve getData method logic
1 parent 5cd17a5 commit b1a336f

1 file changed

Lines changed: 24 additions & 27 deletions

File tree

packages/providers/s3/src/provider.ts

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,47 +122,44 @@ export class S3Provider<ID> extends StorageServiceProvider<ID> {
122122

123123
const variants = await this.createFileUrls(fileId, optimistic)
124124

125-
if (variants.length === 0) {
126-
// If the resource bucket is different from the upload bucket
127-
// we need to check if the file exists in the upload bucket too.
128-
// This is because the file might not have been processed yet.
129-
if (!this.buckets.upload.equals(this.buckets.resource)) {
130-
const exists = await this.buckets.upload.keyExists(
131-
this.buckets.upload.keyResolver.resolve(fileId),
132-
{}
133-
)
134-
135-
if (exists) {
136-
return {
137-
id: fileId,
138-
variants: [],
139-
status: FileStatus.UPLOADED,
140-
}
141-
}
142-
}
143-
125+
if (
126+
variants.length ===
127+
this.configuration.resourceBucket.bucketPath.length
128+
) {
144129
return {
145130
id: fileId,
146-
variants: [],
147-
status: FileStatus.NOT_FOUND,
131+
variants,
132+
status: FileStatus.PROCESSED,
148133
}
149134
}
150135

151-
if (
152-
variants.length !==
153-
this.configuration.resourceBucket.bucketPath.length
154-
) {
136+
if (variants.length > 0) {
155137
return {
156138
id: fileId,
157139
variants,
158140
status: FileStatus.UPLOADED,
159141
}
160142
}
161143

144+
if (!optimistic && !this.buckets.upload.equals(this.buckets.resource)) {
145+
const existsInUploadBucket = await this.buckets.upload.keyExists(
146+
this.buckets.upload.keyResolver.resolve(fileId),
147+
{}
148+
)
149+
150+
if (existsInUploadBucket) {
151+
return {
152+
id: fileId,
153+
variants: [],
154+
status: FileStatus.UPLOADED,
155+
}
156+
}
157+
}
158+
162159
return {
163160
id: fileId,
164-
variants,
165-
status: FileStatus.PROCESSED,
161+
variants: [],
162+
status: FileStatus.NOT_FOUND,
166163
}
167164
}
168165

0 commit comments

Comments
 (0)