-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathcreators.routes.ts
More file actions
165 lines (154 loc) · 4.7 KB
/
Copy pathcreators.routes.ts
File metadata and controls
165 lines (154 loc) · 4.7 KB
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
import { Router } from 'express';
import {
httpListCreators,
httpGetCreator,
httpGetCreatorStats,
httpGetTrendingCreators,
httpGetCreatorLeaderboard,
httpGetCreatorAnalytics,
} from './creators.controllers';
import { httpGetCreatorHolders } from './creator-holders.controller';
import { cacheControl } from '../../middlewares/cache-control.middleware';
import { CREATOR_PUBLIC_ROUTE_CACHE_PRESETS } from '../../constants/creator-public-cache.constants';
import { CREATOR_PUBLIC_ROUTE_NAMES } from '../../constants/creator-public-routes.constants';
import { createCreatorReadMetricsMiddleware } from '../../utils/creator-read-metrics.utils';
import { normalizeTrailingSlash } from '../../middlewares/trailing-slash-normalizer.middleware';
import { validateCreatorParam } from '../../middlewares/creator-param.middleware';
import {
requireCreatorProfileOwnership,
} from '../../middlewares/wallet-ownership.middleware';
import { requireStellarSignature } from '../../middlewares/stellar-signature.middleware';
import { httpBuyCreatorKey } from '../creator/buy.controller';
import { httpCreatePost, httpListPosts } from '../creator/post.controller';
const creatorsRouter = Router();
// Normalize trailing slashes for all creator routes so that, e.g.,
// GET /api/v1/creators/ reaches the same handler as GET /api/v1/creators.
// Scoped to this router to avoid side-effects on other route groups.
creatorsRouter.use(normalizeTrailingSlash);
creatorsRouter.post(
'/:id/buy',
validateCreatorParam('id'),
requireStellarSignature(),
httpBuyCreatorKey
);
creatorsRouter.get('/:id/posts', validateCreatorParam('id'), httpListPosts);
creatorsRouter.post(
'/:id/posts',
validateCreatorParam('id'),
requireStellarSignature(),
httpCreatePost
);
/**
* GET /api/v1/creators
*
* List all creators with pagination and filtering.
* Public endpoint with 5-minute cache.
*/
creatorsRouter.get(
'/',
createCreatorReadMetricsMiddleware('list'),
cacheControl(
CREATOR_PUBLIC_ROUTE_CACHE_PRESETS[CREATOR_PUBLIC_ROUTE_NAMES.LIST]
),
httpListCreators
);
// 405 handler for /
creatorsRouter.all('/', (_req, res) => {
res.set('Allow', 'GET').sendStatus(405);
});
/**
* GET /api/v1/creators/:id/stats
*
* Get public stats for a specific creator.
* Public endpoint with 5-minute cache.
*/
creatorsRouter.get(
'/:id/stats',
validateCreatorParam('id'),
createCreatorReadMetricsMiddleware('detail'),
cacheControl(
CREATOR_PUBLIC_ROUTE_CACHE_PRESETS[CREATOR_PUBLIC_ROUTE_NAMES.GET_STATS]
),
httpGetCreatorStats
);
// 405 handler for /:id/stats
creatorsRouter.all('/:id/stats', (_req, res) => {
res.set('Allow', 'GET').sendStatus(405);
});
/**
* GET /api/v1/creators/:id/holders
*
* Returns a paginated list of wallets that hold keys for a creator.
* Supports ?sort=held_since to surface earliest supporters first.
* Public endpoint with 5-minute cache.
*/
creatorsRouter.get(
'/:id/holders',
validateCreatorParam('id'),
createCreatorReadMetricsMiddleware('holders'),
cacheControl(
CREATOR_PUBLIC_ROUTE_CACHE_PRESETS[CREATOR_PUBLIC_ROUTE_NAMES.GET_HOLDERS]
),
httpGetCreatorHolders
);
// 405 handler for /:id/holders
creatorsRouter.all('/:id/holders', (_req, res) => {
res.set('Allow', 'GET').sendStatus(405);
});
/**
* GET /api/v1/creators/trending
*
* List trending creators ordered by 24h trading volume descending.
*/
creatorsRouter.get(
'/trending',
createCreatorReadMetricsMiddleware('list'),
httpGetTrendingCreators
);
/**
* GET /api/v1/creators/:id/analytics
*
* Returns buy volume and unique buyer count for the authenticated creator.
* Protected route — requires wallet ownership via x-wallet-address header.
*/
creatorsRouter.get(
'/:id/analytics',
validateCreatorParam('id'),
requireCreatorProfileOwnership('id'),
httpGetCreatorAnalytics
);
// 405 handler for /:id/analytics
creatorsRouter.all('/:id/analytics', (_req, res) => {
res.set('Allow', 'GET').sendStatus(405);
});
/**
* GET /api/v1/creators/leaderboard
*
* List creators ranked by holder count descending, tie-broken
* alphabetically by creator address.
*/
creatorsRouter.get(
'/leaderboard',
createCreatorReadMetricsMiddleware('list'),
httpGetCreatorLeaderboard
);
/**
* GET /api/v1/creators/:id
*
* Get public details for a specific creator.
* Public endpoint with 5-minute cache.
*/
creatorsRouter.get(
'/:id',
validateCreatorParam('id'),
createCreatorReadMetricsMiddleware('detail'),
cacheControl(
CREATOR_PUBLIC_ROUTE_CACHE_PRESETS[CREATOR_PUBLIC_ROUTE_NAMES.GET_PROFILE]
),
httpGetCreator
);
// 405 handler for /:id
creatorsRouter.all('/:id', (_req, res) => {
res.set('Allow', 'GET').sendStatus(405);
});
export default creatorsRouter;