김재형

Remove server

...@@ -66,5 +66,6 @@ ...@@ -66,5 +66,6 @@
66 }, 66 },
67 "lint-staged": { 67 "lint-staged": {
68 "*.{js,ts,tsx,json,css,scss}": "prettier --write" 68 "*.{js,ts,tsx,json,css,scss}": "prettier --write"
69 - } 69 + },
70 + "proxy": "http://localhost:8000"
70 } 71 }
......
1 -import { createServer, Model, Response } from "miragejs";
2 -import { ModelDefinition } from "miragejs/-types";
3 -
4 -interface Item {
5 - id: string;
6 - is_folder: boolean;
7 - name: string;
8 - mime_type: string | null;
9 - path: string | null;
10 - parent: string | null;
11 - user_id: string;
12 - size: number;
13 - is_deleted: boolean;
14 - created_timestamp: string;
15 - updated_timestamp: string;
16 - status: boolean;
17 -}
18 -
19 -interface SharedItem {
20 - id: string;
21 - file_id: string;
22 - until: string;
23 - password: string;
24 -}
25 -
26 -interface User {
27 - id: string;
28 - user_id: string;
29 - name: string;
30 - password: string;
31 - total_size: number;
32 - current_size: number;
33 -}
34 -
35 -const ItemModel: ModelDefinition<Item> = Model;
36 -const SharedItemModel: ModelDefinition<SharedItem> = Model;
37 -const UserModel: ModelDefinition<User> = Model;
38 -
39 -createServer({
40 - models: {
41 - item: ItemModel,
42 - shared_item: SharedItemModel,
43 - user: UserModel,
44 - },
45 -
46 - factories: {},
47 -
48 - routes() {
49 - this.get("/items/:item_id/children", (schema, request) => {
50 - const directory = schema.find("item", request.params.item_id);
51 - if (!directory || !directory.is_folder) {
52 - return new Response(
53 - 404,
54 - {
55 - "Content-Type": "application/json",
56 - },
57 - JSON.stringify({
58 - status: 404,
59 - message: "Not Found",
60 - })
61 - );
62 - }
63 -
64 - const list = schema.where("item", { parent: directory.id }).models;
65 - return {
66 - status: 200,
67 - data: {
68 - ...directory.attrs,
69 - count: list.length,
70 - list,
71 - },
72 - };
73 - });
74 -
75 - this.post("/items/:item_id/children", (schema, request) => {
76 - return {
77 - status: 200,
78 - data: {
79 - id: "2341",
80 - is_folder: true,
81 - name: "cloudComputing",
82 - created_timestamp: "2020-05-14T06:20:44Z",
83 - updated_timestamp: "2020-05-14T06:20:44Z",
84 - size: 0,
85 - },
86 - };
87 - });
88 -
89 - this.post("/items/:item_id/upload", (schema, request) => {
90 - return {
91 - status: 200,
92 - data: {
93 - id: "2342",
94 - name: "image.jpg",
95 - is_folder: false,
96 - size: 92929,
97 - path:
98 - "https://presignedurldemo.s3.eu-west-2.amazonaws.com/image.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJJWZ7B6WCRGMKFGQ%2F20180210%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20180210T171315Z&X-Amz-Expires=1800&X-Amz-Signature=12b74b0788aa036bc7c3d03b3f20c61f1f91cc9ad8873e3314255dc479a25351&X-Amz-SignedHeaders=host",
99 - },
100 - };
101 - });
102 -
103 - this.post("/items/:item_id/status", (schema, request) => {
104 - return {
105 - status: 200,
106 - message: "ok",
107 - };
108 - });
109 -
110 - this.post("/items/:item_id/move", (schema, request) => {
111 - return {
112 - status: 200,
113 - data: {
114 - id: "2342",
115 - name: "image.jpg",
116 - is_folder: false,
117 - parentinfo: {
118 - id: "1234",
119 - name: "folder",
120 - is_folder: true,
121 - updated_timestamp: "2020-05-14T06:20:44Z",
122 - },
123 - },
124 - };
125 - });
126 -
127 - this.post("/items/:item_id/copy", (schema, request) => {
128 - return {
129 - status: 200,
130 - data: {
131 - id: "2342",
132 - name: "image.jpg",
133 - is_folder: false,
134 - parentinfo: {
135 - id: "1234",
136 - name: "folder",
137 - is_folder: true,
138 - updated_timestamp: "2020-05-14T06:20:44Z",
139 - },
140 - },
141 - };
142 - });
143 -
144 - this.get("/items/:item_id", (schema, request) => {
145 - return {
146 - status: 200,
147 - data: {
148 - id: "2342",
149 - name: "image.jpg",
150 - is_folder: false,
151 - size: 92929,
152 - path:
153 - "https://presignedurldemo.s3.eu-west-2.amazonaws.com/image.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJJWZ7B6WCRGMKFGQ%2F20180210%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20180210T171315Z&X-Amz-Expires=1800&X-Amz-Signature=12b74b0788aa036bc7c3d03b3f20c61f1f91cc9ad8873e3314255dc479a25351&X-Amz-SignedHeaders=host",
154 - created_timestamp: "2020-05-14T06:20:44Z",
155 - updated_timestamp: "2020-05-14T06:20:44Z",
156 - },
157 - };
158 - });
159 -
160 - this.delete("/items/:item_id", (schema, request) => {
161 - return {
162 - status: 200,
163 - message: "ok",
164 - };
165 - });
166 -
167 - this.post("/items/:item_id/share", (schema, request) => {
168 - return {
169 - status: 200,
170 - user_id: 1,
171 - shared: "2020-05-14T06:20:44Z",
172 - data: {
173 - id: "2342",
174 - name: "image.jpg",
175 - is_folder: false,
176 - size: 92929,
177 - path:
178 - "https://presignedurldemo.s3.eu-west-2.amazonaws.com/image.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJJWZ7B6WCRGMKFGQ%2F20180210%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20180210T171315Z&X-Amz-Expires=1800&X-Amz-Signature=12b74b0788aa036bc7c3d03b3f20c61f1f91cc9ad8873e3314255dc479a25351&X-Amz-SignedHeaders=host",
179 - created_timestamp: "2020-05-14T06:20:44Z",
180 - updated_timestamp: "2020-05-14T06:20:44Z",
181 - },
182 - };
183 - });
184 -
185 - this.post("/shared/:shared_item_id", (schema, request) => {
186 - return {
187 - status: 200,
188 - data: {
189 - name: "image.jpg",
190 - size: 92929,
191 - path:
192 - "https://presignedurldemo.s3.eu-west-2.amazonaws.com/image.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJJWZ7B6WCRGMKFGQ%2F20180210%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20180210T171315Z&X-Amz-Expires=1800&X-Amz-Signature=12b74b0788aa036bc7c3d03b3f20c61f1f91cc9ad8873e3314255dc479a25351&X-Amz-SignedHeaders=host",
193 - },
194 - };
195 - });
196 -
197 - this.post("/items/search", (schema, request) => {
198 - return {
199 - status: 200,
200 - data: {
201 - list: [
202 - {
203 - id: "2341",
204 - is_folder: true,
205 - name: "cloudComputing",
206 - created_timestamp: "2020-05-14T06:20:44Z",
207 - updated_timestamp: "2020-05-14T06:20:44Z",
208 - size: 0,
209 - },
210 - {
211 - id: "2341",
212 - is_folder: true,
213 - name: "cloudComputing",
214 - created_timestamp: "2020-05-14T06:20:44Z",
215 - updated_timestamp: "2020-05-14T06:20:44Z",
216 - size: 0,
217 - },
218 - ],
219 - },
220 - };
221 - });
222 -
223 - this.post("/users/login", (schema, request) => {
224 - const body = JSON.parse(request.requestBody);
225 - const admin = schema.findBy("user", {
226 - user_id: body.user_id,
227 - password: body.password,
228 - });
229 - if (!admin) {
230 - return new Response(
231 - 401,
232 - {
233 - "Content-Type": "application/json",
234 - },
235 - JSON.stringify({
236 - status: 401,
237 - message: "unauthorized",
238 - })
239 - );
240 - }
241 - return {
242 - status: 200,
243 - data: {
244 - access_token:
245 - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
246 - refresh_token:
247 - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
248 - expiration: "2020-05-14T07:23:24Z",
249 - },
250 - };
251 - });
252 -
253 - this.post("/users/renew", (schema, request) => {
254 - return {
255 - status: 200,
256 - data: {
257 - access_token:
258 - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
259 - refresh_token:
260 - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
261 - expiration: "2020-05-14T07:23:24Z",
262 - },
263 - };
264 - });
265 -
266 - this.post("/users/signup", (schema, request) => {
267 - return {
268 - status: 200,
269 - message: "completed",
270 - data: {
271 - user_id: "test",
272 - name: "test",
273 - total_size: 1099511627776,
274 - current_size: 0,
275 - },
276 - };
277 - });
278 -
279 - this.post("/users/:user_id", (schema, request) => {
280 - return {
281 - status: 200,
282 - data: {
283 - id: "123",
284 - user_id: "test",
285 - name: "test",
286 - total_size: 1099511627776,
287 - current_size: 0,
288 - },
289 - };
290 - });
291 - },
292 -
293 - seeds(server) {
294 - const user = server.create("user", {
295 - id: "1",
296 - user_id: "admin",
297 - name: "테스트",
298 - password: "password",
299 - total_size: 1024 * 1024 * 1024 * 5, // 5GB
300 - current_size: 1024 * 1024 * 1024 * 1, // 1GB
301 - });
302 -
303 - const rootDir = server.create("item", {
304 - id: "1",
305 - is_folder: true,
306 - name: "root",
307 - mime_type: null,
308 - path: null,
309 - parent: null,
310 - user_id: user.id,
311 - size: 0,
312 - is_deleted: false,
313 - created_timestamp: "2020-05-14T06:20:44Z",
314 - updated_timestamp: "2020-05-14T06:20:44Z",
315 - status: true,
316 - });
317 -
318 - server.create("item", {
319 - id: "2",
320 - is_folder: false,
321 - name: "image.jpg",
322 - mime_type: "image/jpeg",
323 - path: "",
324 - parent: rootDir.id,
325 - user_id: user.id,
326 - size: 1024 * 1024 * 5,
327 - is_deleted: false,
328 - created_timestamp: "2020-05-14T06:20:44Z",
329 - updated_timestamp: "2020-05-14T06:20:44Z",
330 - status: true,
331 - });
332 - },
333 -});