@@ -50,7 +50,8 @@ export class AttachmentManager {
50
50
}
51
51
} )
52
52
53
- return new Attachment ( this . #drive, attributes )
53
+ const attachment = new Attachment ( this . #drive, attributes )
54
+ return this . #configureAttachment( attachment )
54
55
}
55
56
56
57
async createFromFile ( file : MultipartFile ) {
@@ -65,7 +66,8 @@ export class AttachmentManager {
65
66
throw new errors . ENOENT ( )
66
67
}
67
68
68
- return new Attachment ( this . #drive, attributes , file . tmpPath )
69
+ const attachment = new Attachment ( this . #drive, attributes , file . tmpPath )
70
+ return this . #configureAttachment( attachment )
69
71
}
70
72
71
73
async createFromBuffer ( buffer : Buffer , name ?: string ) {
@@ -75,7 +77,8 @@ export class AttachmentManager {
75
77
76
78
const attributes = await createAttachmentAttributes ( buffer , name )
77
79
78
- return new Attachment ( this . #drive, attributes , buffer )
80
+ const attachment = new Attachment ( this . #drive, attributes , buffer )
81
+ return this . #configureAttachment( attachment )
79
82
}
80
83
81
84
async createFromBase64 ( data : string , name ?: string ) {
@@ -147,9 +150,7 @@ export class AttachmentManager {
147
150
148
151
async delete ( attachment : AttachmentBase ) {
149
152
if ( attachment . path ) {
150
- const filePath = attachment . path
151
-
152
- await attachment . getDisk ( ) . delete ( filePath )
153
+ await attachment . getDisk ( ) . delete ( attachment . path )
153
154
154
155
if ( attachment instanceof Attachment ) {
155
156
if ( attachment . variants ) {
@@ -158,5 +159,27 @@ export class AttachmentManager {
158
159
}
159
160
}
160
161
}
162
+
163
+ if ( attachment . originalPath ) {
164
+ await attachment . getDisk ( ) . delete ( attachment . originalPath )
165
+ }
166
+ }
167
+
168
+ // private methods
169
+
170
+ #configureAttachment( attachment : AttachmentType ) {
171
+ if ( this . #config. meta !== undefined ) {
172
+ attachment . setOptions ( { meta : this . #config. meta } )
173
+ }
174
+
175
+ if ( this . #config. rename !== undefined ) {
176
+ attachment . setOptions ( { rename : this . #config. rename } )
177
+ }
178
+
179
+ if ( this . #config. preComputeUrl !== undefined ) {
180
+ attachment . setOptions ( { preComputeUrl : this . #config. preComputeUrl } )
181
+ }
182
+
183
+ return attachment
161
184
}
162
185
}
0 commit comments