Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
C_Team_KhuDrive
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
김재형
2020-06-08 15:53:12 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
924670aa7c2a66ae5e44dfcc5cfc2ebe5d56a07f
924670aa
1 parent
14bf9aaa
Implement dummy file api
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
126 additions
and
18 deletions
frontend/src/server.ts
frontend/src/server.ts
View file @
924670a
import
{
createServer
,
Model
}
from
"miragejs"
;
import
{
createServer
,
Model
,
Response
}
from
"miragejs"
;
import
{
ModelDefinition
}
from
"miragejs/-types"
;
interface
Item
{
...
...
@@ -51,10 +51,16 @@ createServer({
this
.
get
(
"/items/:item_id/children"
,
(
schema
,
request
)
=>
{
const
directory
=
schema
.
find
(
"item"
,
request
.
params
.
item_id
);
if
(
!
directory
||
!
directory
.
is_folder
)
{
return
{
status
:
404
,
message
:
"Not Found"
,
};
return
new
Response
(
404
,
{
"Content-Type"
:
"application/json"
,
},
JSON
.
stringify
({
status
:
404
,
message
:
"Not Found"
,
})
);
}
const
list
=
schema
.
where
(
"item"
,
{
parent
:
directory
.
id
}).
models
;
...
...
@@ -68,23 +74,125 @@ createServer({
};
});
this
.
post
(
"/items/:item_id/children"
,
(
schema
,
request
)
=>
{
return
{
status
:
200
,
data
:
{
id
:
"2341"
,
is_folder
:
true
,
name
:
"cloudComputing"
,
created_timestamp
:
"2020-05-14T06:20:44Z"
,
updated_timestamp
:
"2020-05-14T06:20:44Z"
,
size
:
0
,
},
};
});
this
.
post
(
"/items/:item_id/upload"
,
(
schema
,
request
)
=>
{
return
{
status
:
200
,
data
:
{
id
:
"2342"
,
name
:
"image.jpg"
,
is_folder
:
false
,
size
:
92929
,
path
:
"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"
,
},
};
});
this
.
post
(
"/items/:item_id/status"
,
(
schema
,
request
)
=>
{
return
{
status
:
200
,
message
:
"ok"
,
};
});
this
.
post
(
"/items/:item_id/move"
,
(
schema
,
request
)
=>
{
return
{
status
:
200
,
data
:
{
id
:
"2342"
,
name
:
"image.jpg"
,
is_folder
:
false
,
parentinfo
:
{
id
:
"1234"
,
name
:
"folder"
,
is_folder
:
true
,
updated_timestamp
:
"2020-05-14T06:20:44Z"
,
},
},
};
});
this
.
post
(
"/items/:item_id/copy"
,
(
schema
,
request
)
=>
{
return
{
status
:
200
,
data
:
{
id
:
"2342"
,
name
:
"image.jpg"
,
is_folder
:
false
,
parentinfo
:
{
id
:
"1234"
,
name
:
"folder"
,
is_folder
:
true
,
updated_timestamp
:
"2020-05-14T06:20:44Z"
,
},
},
};
});
this
.
get
(
"/items/:item_id"
,
(
schema
,
request
)
=>
{
return
{
status
:
200
,
data
:
{
id
:
"2342"
,
name
:
"image.jpg"
,
is_folder
:
false
,
size
:
92929
,
path
:
"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"
,
created_timestamp
:
"2020-05-14T06:20:44Z"
,
updated_timestamp
:
"2020-05-14T06:20:44Z"
,
},
};
});
this
.
delete
(
"/items/:item_id"
,
(
schema
,
request
)
=>
{
return
{
status
:
200
,
message
:
"ok"
,
};
});
this
.
post
(
"/users/login"
,
(
schema
,
request
)
=>
{
const
body
=
JSON
.
parse
(
request
.
requestBody
);
if
(
body
.
user_id
===
"admin"
&&
body
.
password
===
"password"
)
{
return
{
status
:
200
,
data
:
{
access_token
:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
,
refresh_token
:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
,
expiration
:
"2020-05-14T07:23:24Z
"
,
const
admin
=
schema
.
findBy
(
"user"
,
{
user_id
:
body
.
user_id
,
password
:
body
.
password
,
});
if
(
!
admin
)
{
return
new
Response
(
401
,
{
"Content-Type"
:
"application/json
"
,
},
};
JSON
.
stringify
({
status
:
401
,
message
:
"unauthorized"
,
})
);
}
return
{
status
:
401
,
message
:
"unauthorized"
,
status
:
200
,
data
:
{
access_token
:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
,
refresh_token
:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
,
expiration
:
"2020-05-14T07:23:24Z"
,
},
};
});
},
...
...
@@ -92,7 +200,7 @@ createServer({
seeds
(
server
)
{
const
user
=
server
.
create
(
"user"
,
{
id
:
"1"
,
user_id
:
"
test
"
,
user_id
:
"
admin
"
,
name
:
"테스트"
,
password
:
"password"
,
total_size
:
1024
*
1024
*
1024
*
5
,
// 5GB
...
...
Please
register
or
login
to post a comment