Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions internal/aistudio/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,15 @@ func (copies *TemporaryFileCopies) Cleanup() error {
deleteErr := copies.client.deleteDriveFile(
cleanupCtx, copies.lease.Account().ID, copy.token, copy.id,
)
if driveFileNotFound(deleteErr, "DriveDelete") {
deleteErr = nil
}
bindErr := error(nil)
if deleteErr == nil && copy.bound {
bindErr = copies.lease.pool.unbindResourceContext(cleanupCtx, copy.id)
if errors.Is(bindErr, ErrResourceNotFound) {
bindErr = nil
}
}
if deleteErr != nil && copy.media != nil {
bindErr = copies.lease.bindInlineMedia(context.Background(), copy.media.file, copy.media.key, copy.media.size)
Expand Down Expand Up @@ -891,6 +897,12 @@ func (l *AccountLease) bindInlineMedia(ctx context.Context, file FileRef, key in
if owner, exists := l.pool.resources[file.ID]; exists && owner != accountID {
return false, nil, fmt.Errorf("资源 %s 已绑定账户 %s", file.ID, owner)
}
for existingID, binding := range runtimeState.Resources {
if existingID != file.ID && binding.Kind == "inline-media" &&
binding.MIME == key.mime && binding.SHA256 == key.sha256 && binding.DisplayName == key.name {
delete(runtimeState.Resources, existingID)
}
}
now := time.Now().UTC()
runtimeState.Resources[file.ID] = ResourceBinding{
Kind: "inline-media", Name: file.Name, MIME: file.MIME, Size: size, SHA256: key.sha256, CreatedAt: now, UsedAt: now, DisplayName: key.name,
Expand Down
Loading