-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextend.php
130 lines (115 loc) · 5.38 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
<?php
/*
* This file is part of acpl/flarum-lscache.
*
* Copyright (c) android.com.pl.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace ACPL\FlarumLSCache;
use ACPL\FlarumLSCache\Api\Controller\{LSCacheCsrfResponseController, PurgeLSCacheController};
use ACPL\FlarumLSCache\Command\LSCachePurgeCommand;
use ACPL\FlarumLSCache\Compatibility\{
ClarkWinkelmann\AuthorChangeEventSubscriber,
Flarum\LikesEventSubscriber,
Flarum\TagsEventSubscriber,
FoF\MasqueradePurgeCacheMiddleware,
FoF\MergeDiscussionsEventSubscriber,
SychO\MovePostsSubscriber,
v17development\FlarumBlogEventSubscriber
};
use ACPL\FlarumLSCache\Listener\{
ClearingCacheListener,
DiscussionEventSubscriber,
PostEventSubscriber,
UserEventSubscriber
};
use ACPL\FlarumLSCache\Middleware\{
CacheControlMiddleware,
CacheTagsMiddleware,
LoginMiddleware,
LogoutMiddleware,
PurgeCacheMiddleware,
StatusCodesCacheMiddleware,
VaryCookieMiddleware
};
use Flarum\Api\Serializer\UserSerializer;
use Flarum\Extend;
use Flarum\Foundation\Event\ClearingCache;
use Flarum\Http\Middleware\CheckCsrfToken;
use Flarum\Http\Middleware\InjectActorReference;
use Flarum\Settings\Event\Saved;
return [
(new Extend\Frontend('admin'))->js(__DIR__.'/js/dist/admin.js'),
(new Extend\Frontend('forum'))->js(__DIR__.'/js/dist/forum.js'),
new Extend\Locales(__DIR__.'/locale'),
// Settings
(new Extend\Settings())
->default('acpl-lscache.cache_enabled', true)
->default('acpl-lscache.public_cache_ttl', 604_800)
->default('acpl-lscache.clearing_cache_listener', true)
->default('acpl-lscache.drop_qs', implode("\n", LSCache::DEFAULT_DROP_QS))
->default('acpl-lscache.status_codes_cache', "404 3600\n403 3600\n500 120"),
(new Extend\Event())->listen(Saved::class, Listener\UpdateSettingsListener::class),
// Permissions
(new Extend\ApiSerializer(UserSerializer::class))
->attribute(
'canPurgeLSCache',
fn (UserSerializer $serializer) => $serializer->getActor()->can('lscache.purge'),
),
// Vary cookie
(new Extend\Middleware('forum'))->insertAfter(CheckCsrfToken::class, VaryCookieMiddleware::class),
(new Extend\Middleware('admin'))->insertAfter(CheckCsrfToken::class, VaryCookieMiddleware::class),
(new Extend\Middleware('api'))->insertAfter(CheckCsrfToken::class, VaryCookieMiddleware::class),
// LogIn
(new Extend\Middleware('forum'))->insertAfter(VaryCookieMiddleware::class, LoginMiddleware::class),
// LogOut
(new Extend\Middleware('forum'))->insertAfter(VaryCookieMiddleware::class, LogoutMiddleware::class),
// Tag routes
(new Extend\Middleware('forum'))->add(CacheTagsMiddleware::class),
(new Extend\Middleware('api'))->add(CacheTagsMiddleware::class),
// Cache status codes
(new Extend\Middleware('forum'))->insertAfter(InjectActorReference::class, StatusCodesCacheMiddleware::class),
(new Extend\Middleware('admin'))->insertAfter(InjectActorReference::class, StatusCodesCacheMiddleware::class),
(new Extend\Middleware('api'))->insertAfter(InjectActorReference::class, StatusCodesCacheMiddleware::class),
// Cache routes
(new Extend\Middleware('forum'))->insertAfter(VaryCookieMiddleware::class, CacheControlMiddleware::class),
(new Extend\Middleware('api'))->insertAfter(VaryCookieMiddleware::class, CacheControlMiddleware::class),
// A workaround for the CSRF cache issue. The JS script fetches this path to update the CSRF
(new Extend\Routes('api'))->get('/lscache-csrf', 'lscache.csrf', LSCacheCsrfResponseController::class),
// Purge cache on update
(new Extend\Middleware('forum'))->add(PurgeCacheMiddleware::class),
(new Extend\Middleware('admin'))->add(PurgeCacheMiddleware::class),
(new Extend\Middleware('api'))->add(PurgeCacheMiddleware::class),
// Purge cache
(new Extend\Routes('api'))->get('/lscache-purge', 'lscache.purge', PurgeLSCacheController::class),
(new Extend\Console)->command(LSCachePurgeCommand::class),
(new Extend\Event)->listen(ClearingCache::class, ClearingCacheListener::class),
(new Extend\Event)->subscribe(DiscussionEventSubscriber::class),
(new Extend\Event)->subscribe(PostEventSubscriber::class),
(new Extend\Event)->subscribe(UserEventSubscriber::class),
// Extensions
(new Extend\Conditional)
->whenExtensionEnabled('flarum-likes', [
(new Extend\Event)->subscribe(LikesEventSubscriber::class),
])
->whenExtensionEnabled('flarum-tags', [
(new Extend\Event)->subscribe(TagsEventSubscriber::class),
])
->whenExtensionEnabled('fof-masquerade', [
(new Extend\Middleware('api'))->add(MasqueradePurgeCacheMiddleware::class),
])
->whenExtensionEnabled('fof-merge-discussions', [
(new Extend\Event)->subscribe(MergeDiscussionsEventSubscriber::class),
])
->whenExtensionEnabled('v17development-blog', [
(new Extend\Event)->subscribe(FlarumBlogEventSubscriber::class),
])
->whenExtensionEnabled('clarkwinkelmann-author-change', [
(new Extend\Event)->subscribe(AuthorChangeEventSubscriber::class),
])
->whenExtensionEnabled('sycho-move-posts', [
(new Extend\Event)->subscribe(MovePostsSubscriber::class),
]),
];