-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
extend.php
136 lines (110 loc) · 5.58 KB
/
extend.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
<?php
/*
* This file is part of fof/upload.
*
* Copyright (c) FriendsOfFlarum.
* Copyright (c) Flagrow.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FoF\Upload;
use Flarum\Api\Controller\ListDiscussionsController;
use Flarum\Api\Controller\ListPostsController;
use Flarum\Api\Controller\ShowForumController;
use Flarum\Api\Controller\ShowUserController;
use Flarum\Api\Serializer\CurrentUserSerializer;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Api\Serializer\UserSerializer;
use Flarum\Extend;
use Flarum\Gdpr\Extend\UserData;
use Flarum\Post\Event\Posted;
use Flarum\Post\Event\Revised;
use Flarum\Settings\Event\Deserializing;
use Flarum\User\User;
use FoF\Upload\Events\File\WillBeUploaded;
use FoF\Upload\Exceptions\ExceptionHandler;
use FoF\Upload\Exceptions\InvalidUploadException;
use FoF\Upload\Extend\SvgSanitizer;
use FoF\Upload\Extenders\LoadFilesRelationship;
use FoF\Upload\Helpers\Util;
return [
(new Extend\Frontend('admin'))
->css(__DIR__.'/resources/less/admin.less')
->js(__DIR__.'/js/dist/admin.js'),
(new Extend\Frontend('forum'))
->css(__DIR__.'/resources/less/forum.less')
->js(__DIR__.'/js/dist/forum.js'),
new Extend\Locales(__DIR__.'/resources/locale'),
(new Extend\Routes('api'))
->get('/fof/uploads', 'fof-upload.list', Api\Controllers\ListUploadsController::class)
->post('/fof/upload', 'fof-upload.upload', Api\Controllers\UploadController::class)
->post('/fof/watermark', 'fof-upload.watermark', Api\Controllers\WatermarkUploadController::class)
->delete('/fof/watermark', 'fof-upload.watermark.delete', Api\Controllers\WatermarkDeleteController::class)
->get('/fof/download/{uuid}/{post}/{csrf}', 'fof-upload.download', Api\Controllers\DownloadController::class)
->get('/fof/download/{uuid}', 'fof-upload.download.uuid', Api\Controllers\DownloadController::class)
->post('/fof/upload/inspect-mime', 'fof-upload.inspect-mime', Api\Controllers\InspectMimeController::class)
->patch('/fof/upload/hide', 'fof-upload.hide', Api\Controllers\HideUploadFromMediaManagerController::class)
->get('/fof/upload/shared-files', 'fof-upload.shared-files.index', Api\Controllers\ListSharedUploadsController::class)
->delete('/fof/upload/delete/{uuid}', 'fof-upload.delete', Api\Controllers\DeleteFileController::class),
// Disabled pending https://github.com/FriendsOfFlarum/upload/issues/374
// (new Extend\Console())
// ->command(Console\MapFilesCommand::class),
(new Extend\Csrf())
->exemptRoute('fof-upload.download'),
(new Extend\Model(User::class))
->cast('foffiles_current_count', 'int')
->cast('foffiles_count', 'int')
->hasMany('foffiles', File::class, 'actor_id')
->relationship('foffilesCurrent', function (User $model) {
return $model->foffiles()->where('hidden', false);
}),
(new Extend\ApiController(ShowUserController::class))
->prepareDataForSerialization([LoadFilesRelationship::class, 'countRelations']),
(new Extend\ApiController(ShowForumController::class))
->prepareDataForSerialization([LoadFilesRelationship::class, 'countRelations']),
(new Extend\ApiController(ListDiscussionsController::class))
->prepareDataForSerialization([LoadFilesRelationship::class, 'countRelations']),
(new Extend\ApiController(ListPostsController::class))
->prepareDataForSerialization([LoadFilesRelationship::class, 'countRelations']),
(new Extend\ApiSerializer(ForumSerializer::class))
->attributes(Extenders\AddForumAttributes::class),
(new Extend\Event())
->listen(Deserializing::class, Listeners\AddAvailableOptionsInAdmin::class)
->listen(Posted::class, Listeners\LinkImageToPostOnSave::class)
->listen(Revised::class, Listeners\LinkImageToPostOnSave::class)
->listen(WillBeUploaded::class, Listeners\AddImageProcessor::class),
(new Extend\Filesystem())
->disk('private-shared', Extenders\PrivateSharedDiskConfig::class),
(new Extend\ServiceProvider())
->register(Providers\UtilProvider::class)
->register(Providers\StorageServiceProvider::class)
->register(Providers\DownloadProvider::class)
->register(Providers\SanitizerProvider::class),
(new Extend\View())
->namespace('fof-upload.templates', __DIR__.'/resources/templates'),
(new Extend\ApiSerializer(CurrentUserSerializer::class))
->attributes(Extenders\AddCurrentUserAttributes::class),
(new Extend\ApiSerializer(UserSerializer::class))
->attributes(Extenders\AddUserAttributes::class),
(new Extend\Formatter())
->render(Formatter\TextPreview\FormatTextPreview::class),
(new SvgSanitizer())
->allowTag('animate'),
(new Extend\ErrorHandling())
->handler(InvalidUploadException::class, ExceptionHandler::class),
(new Extend\Settings())
->default('fof-upload.maxFileSize', Util::DEFAULT_MAX_FILE_SIZE)
->default('fof-upload.s3CustomUrl', ''), // Default to empty, meaning use AWS default URL
new Extenders\AddPostDownloadTags(),
new Extenders\CreateStorageFolder('tmp'),
(new Extend\Filesystem())
->disk('private-shared', Extenders\PrivateSharedDiskConfig::class),
(new Extend\Policy())
->modelPolicy(File::class, Access\FilePolicy::class),
(new Extend\Conditional())
->whenExtensionEnabled('flarum-gdpr', fn () => [
(new UserData())
->addType(Data\Uploads::class),
]),
];