@@ -13,6 +13,7 @@ import type {
13
13
} from '../types/attachment.js'
14
14
import type { Exif , Input } from '../types/input.js'
15
15
16
+ import path from 'node:path'
16
17
import { cuid } from '@adonisjs/core/helpers'
17
18
import { defaultOptionsDecorator } from '../utils/default_values.js'
18
19
@@ -21,13 +22,14 @@ export class AttachmentBase implements AttachmentBaseInterface {
21
22
22
23
input ?: Input
23
24
24
- name : string
25
+ #name: string
26
+ #folder?: string
27
+
25
28
size : number
26
29
extname : string
27
30
mimeType : string
28
31
meta ?: Exif
29
- folder ?: string
30
- path ?: string
32
+ originalPath ?: string
31
33
url ?: string
32
34
33
35
options ?: LucidOptions
@@ -39,20 +41,42 @@ export class AttachmentBase implements AttachmentBaseInterface {
39
41
this . meta = attributes . meta
40
42
this . extname = attributes . extname
41
43
this . mimeType = attributes . mimeType
42
- this . folder = attributes . folder
43
- this . path = attributes . path
44
+ this . originalPath = attributes . path
44
45
45
- this . options = defaultOptionsDecorator
46
+ this . #folder = attributes . folder
47
+ if ( attributes . name ) {
48
+ this . #name = attributes . name
49
+ } else {
50
+ this . #name = `${ cuid ( ) } .${ this . extname } `
51
+ }
46
52
53
+ this . options = defaultOptionsDecorator
47
54
this . drive = drive
55
+ }
48
56
49
- if ( attributes . name ) {
50
- this . name = attributes . name
51
- } else {
52
- this . name = `${ cuid ( ) } .${ this . extname } `
57
+ /**
58
+ * Getters
59
+ */
60
+
61
+ get name ( ) : string {
62
+ return this . #name
63
+ }
64
+
65
+ get folder ( ) : string | undefined {
66
+ if ( this . options ) {
67
+ return this . options ?. folder
53
68
}
69
+ return this . #folder
54
70
}
55
71
72
+ get path ( ) : string {
73
+ return path . join ( this . folder ! , this . name )
74
+ }
75
+
76
+ /**
77
+ * Methods
78
+ */
79
+
56
80
getDisk ( ) {
57
81
return this . drive . use ( this . options ?. disk )
58
82
}
@@ -73,6 +97,10 @@ export class AttachmentBase implements AttachmentBaseInterface {
73
97
return this
74
98
}
75
99
100
+ /**
101
+ *
102
+ */
103
+
76
104
toObject ( ) : AttachmentBaseAttributes {
77
105
return {
78
106
name : this . name ,
0 commit comments