-
Notifications
You must be signed in to change notification settings - Fork 100
/
mediable.php
305 lines (285 loc) · 8.96 KB
/
mediable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
return [
/*
* The database connection name to use
*
* Set to `null` in order to use the default database connection
*/
'connection_name' => null,
/*
* FQCN of the model to use for media
*
* Should extend `Plank\Mediable\Media`
*/
'model' => Plank\Mediable\Media::class,
/*
* Name to be used for mediables joining table
*/
'mediables_table' => 'mediables',
/*
* Filesystem disk to use if none is specified
*/
'default_disk' => 'public',
/*
* Filesystems that can be used for media storage
*
* Uploader will throw an exception if a disk not in this list is selected
*/
'allowed_disks' => [
'public',
],
/*
* The maximum file size in bytes for a single uploaded file
*/
'max_size' => 1024 * 1024 * 10,
/*
* What to do if a duplicate file is uploaded.
*
* Options include:
*
* * `'increment'`: the new file's name is given an incrementing suffix
* * `'replace'` : the old file and media model is deleted
* * `'error'`: an Exception is thrown
*/
'on_duplicate' => Plank\Mediable\MediaUploader::ON_DUPLICATE_INCREMENT,
/*
* Reject files unless both their mime and extension are recognized and both match a single aggregate type
*/
'strict_type_checking' => false,
/*
* Reject files whose mime type or extension is not recognized
* if true, files will be given a type of `'other'`
*/
'allow_unrecognized_types' => false,
/**
* Prefer the client-provided MIME type over the one inferred from the file contents, if provided
* May be slightly faster to compute, but is not guaranteed to be accurate if the source is untrusted
*/
'prefer_client_mime_type' => false,
/*
* Only allow files with specific MIME type(s) to be uploaded
*/
'allowed_mime_types' => [],
/*
* Only allow files with specific file extension(s) to be uploaded
*/
'allowed_extensions' => [],
/*
* Only allow files matching specific aggregate type(s) to be uploaded
*/
'allowed_aggregate_types' => [],
/*
* List of aggregate types recognized by the application
*
* Each type should list the MIME types and extensions
* that should be recognized for the type
*/
'aggregate_types' => [
Plank\Mediable\Media::TYPE_IMAGE => [
'mime_types' => [
'image/jpeg',
'image/png',
'image/gif',
],
'extensions' => [
'jpg',
'jpeg',
'png',
'gif',
]
],
Plank\Mediable\Media::TYPE_IMAGE_VECTOR => [
'mime_types' => [
'image/svg+xml',
],
'extensions' => [
'svg',
]
],
Plank\Mediable\Media::TYPE_PDF => [
'mime_types' => [
'application/pdf',
],
'extensions' => [
'pdf',
]
],
Plank\Mediable\Media::TYPE_AUDIO => [
'mime_types' => [
'audio/aac',
'audio/ogg',
'audio/mpeg',
'audio/mp3',
'audio/mpeg',
'audio/wav'
],
'extensions' => [
'aac',
'ogg',
'oga',
'mp3',
'wav',
]
],
Plank\Mediable\Media::TYPE_VIDEO => [
'mime_types' => [
'video/mp4',
'video/mpeg',
'video/ogg',
'video/webm'
],
'extensions' => [
'mp4',
'm4v',
'mov',
'ogv',
'webm'
]
],
Plank\Mediable\Media::TYPE_ARCHIVE => [
'mime_types' => [
'application/zip',
'application/x-compressed-zip',
'multipart/x-zip',
],
'extensions' => [
'zip',
]
],
Plank\Mediable\Media::TYPE_DOCUMENT => [
'mime_types' => [
'text/plain',
'application/plain',
'text/xml',
'text/json',
'application/json',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
],
'extensions' => [
'doc',
'docx',
'txt',
'text',
'xml',
'json',
]
],
Plank\Mediable\Media::TYPE_SPREADSHEET => [
'mime_types' => [
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
],
'extensions' => [
'xls',
'xlsx',
]
],
Plank\Mediable\Media::TYPE_PRESENTATION => [
'mime_types' =>
[
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow'
],
'extensions' =>
[
'ppt',
'pptx',
'ppsx',
]
],
],
/*
* List of adapters to use for various source inputs
*
* Adapters can map either to a class or a pattern (regex)
*/
'source_adapters' => [
'class' => [
Symfony\Component\HttpFoundation\File\UploadedFile::class => Plank\Mediable\SourceAdapters\UploadedFileAdapter::class,
Symfony\Component\HttpFoundation\File\File::class => Plank\Mediable\SourceAdapters\FileAdapter::class,
Psr\Http\Message\StreamInterface::class => Plank\Mediable\SourceAdapters\StreamAdapter::class,
],
'pattern' => [
'^https?://' => Plank\Mediable\SourceAdapters\RemoteUrlAdapter::class,
'^/' => Plank\Mediable\SourceAdapters\LocalPathAdapter::class,
'^[a-zA-Z]:\\\\' => Plank\Mediable\SourceAdapters\LocalPathAdapter::class,
'^data:/?/?[^,]*,' => Plank\Mediable\SourceAdapters\DataUrlAdapter::class,
],
],
/*
* List of URL Generators to use for handling various filesystem drivers
*
*/
'url_generators' => [
'local' => Plank\Mediable\UrlGenerators\LocalUrlGenerator::class,
's3' => Plank\Mediable\UrlGenerators\S3UrlGenerator::class,
],
/**
* Should mediable instances automatically reload their media relationships after modification are made to a tag.
*
* If true, will automatically reload media the next time `getMedia()`, `getMediaMatchAll()` or `getAllMediaByTag()` are called.
*/
'rehydrate_media' => true,
/**
* Detach associated media when mediable model is soft deleted.
*/
'detach_on_soft_delete' => false,
/**
* Prevents loading migrations from the package.
*
* Use this if you are renaming the published migrations and want to prevent them from being loaded twice.
*/
'ignore_migrations' => false,
/**
* Configuration for image optimization
*/
'image_optimization' => [
/**
* Whether to apply image optimization after performing image manipulations by default
*/
'enabled' => true,
/**
* array of optimizers to use, which should implement \Spatie\ImageOptimizer\Optimizer
* Each can be passed an array of command line arguments to be passed to the optimizer
*/
'optimizers' => [
\Spatie\ImageOptimizer\Optimizers\Jpegoptim::class => [
'--max=85',
'--strip-all',
'--all-progressive',
],
\Spatie\ImageOptimizer\Optimizers\Pngquant::class => [
'--quality=85',
'--force',
'--skip-if-larger',
],
\Spatie\ImageOptimizer\Optimizers\Optipng::class => [
'-i0',
'-o2',
'-quiet',
],
\Spatie\ImageOptimizer\Optimizers\Gifsicle::class => [
'-b',
'-O3',
],
\Spatie\ImageOptimizer\Optimizers\Cwebp::class => [
'-q 80',
'-m 6',
'-pass 10',
'-mt',
],
\Spatie\ImageOptimizer\Optimizers\Avifenc::class => [
'-a cq-level=23',
'-j all',
'--min 0',
'--max 63',
'--minalpha 0',
'--maxalpha 63',
'-a end-usage=q',
'-a tune=ssim',
],
],
]
];