신은섭(Shin Eun Seop)

add all api spec

import java.util.Scanner;
class calculator{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.print("Input first args: ");
float num1 = scn.nextFloat();
System.out.print("Input second args: ");
float num2 = scn.nextFloat();
System.out.print("Input Operator(+,-,/,*): ");
String oper = scn.next();
float result = 0.0f;
switch (oper) {
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "/":
result = num1 / num2;
break;
case "*":
result = num1 * num2;
break;
default:
break;
}
System.out.println("Result is " + result);
scn.close();
}
}
\ No newline at end of file
......@@ -4,10 +4,6 @@ from dcloud import aws_conf
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '534f6m=i@*)=q3kuwlge1m3c+@^cabr3ttcx*omv^+dorydjfr'
......@@ -16,9 +12,7 @@ DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
......@@ -112,6 +106,8 @@ USE_TZ = True
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
# Login redirect
......
import java.util.Scanner;
class calculator{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.print("Input first args: ");
float num1 = scn.nextFloat();
System.out.print("Input second args: ");
float num2 = scn.nextFloat();
System.out.print("Input Operator(+,-,/,*): ");
String oper = scn.next();
float result = 0.0f;
switch (oper) {
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "/":
result = num1 / num2;
break;
case "*":
result = num1 * num2;
break;
default:
break;
}
System.out.println("Result is " + result);
scn.close();
}
}
\ No newline at end of file
......@@ -2,12 +2,13 @@ from django.db import models
# Create your models here.
class File(models.Model):
file = models.FileField(blank=False, null=False)
# title = models.CharField(max_length=100)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
title = models.CharField(max_length=100)
# modified = models.DateTimeField(auto_now=True)
# file_name = models.CharField(max_length=100, primary_key=True)
object_key = models.CharField(max_length=1025)
# object_key = models.CharField(max_length=1025)
# owner = models.ForeignKey('auth.User', related_name='snippets', on_delete=models.CASCADE)
class Meta:
......
......@@ -27,5 +27,24 @@ def list_path(bucket, user, path):
return {'files':files}
def upload_file(bucket, user, local_path, key):
return S3.upload_file(local_path, bucket, user+"/"+key)
def download_file(bucket, user, local_path, key):
return S3.download_file(bucket, user+"/"+key, local_path)
def delete_path(bucket, user, path):
return S3.delete_object(Bucket=bucket, Key='{}/{}'.format(user, path))
return S3.delete_object(Bucket=bucket, Key=user+"/"+path)
def make_directory(bucket, user, path):
return S3.put_object(Bucket=BUCKET, Key=user+"/"+path)
#
def move_file(bucket, user, old_path, new_path):
S3.copy_object(Bucket=bucket, CopySource=bucket+"/"+user+"/"+old_path, Key=user+"/"+new_path)
S3.delete_object(Bucket=bucket, Key=user+"/"+old_path)
return
def copy_file(bucket, user, old_path, new_path):
S3.copy_object(Bucket=bucket, CopySource=bucket+"/"+user+"/"+old_path, Key=user+"/"+new_path)
return
......
......@@ -7,4 +7,4 @@ class FileSerializer(serializers.ModelSerializer):
class Meta:
model = File
fields = ('created', 'updated', 'object_key')
fields = ('file', 'created')
......
......@@ -3,11 +3,12 @@ from django.shortcuts import redirect
from rest_framework.urlpatterns import format_suffix_patterns
from restful import views
urlpatterns = [
url(r'^list/(?P<path>([a-zA-z0-9가-힣._-]*/)*)$', views.FileList.as_view(), name='file-list'),
# url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view()),
file_regex = '[\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]'
url(r'^file/(?P<path>([a-zA-z0-9가-힣._-]*/*)*)$', views.FileDetail.as_view(), name='file-detail')
urlpatterns = [
url(r'^list/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.FileList.as_view(), name='file-list'),
url(r'^file/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)$', views.FileDetail.as_view(), name='file-detail'),
url(r'^file-mod/(?P<old_path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)&(?P<new_path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]]*/*)*)$', views.FileCopyMove.as_view(), name='file-copy-move')
]
urlpatterns = format_suffix_patterns(urlpatterns)
\ No newline at end of file
......
......@@ -13,44 +13,74 @@ class FileList(APIView):
List all file, or create a new snippet.
"""
"""
list files or view detail
"""
def get(self, request, path="/", format=None):
data = s3_interface.list_path(s3_interface.BUCKET, 'test1', path)
user = request.user
data = s3_interface.list_path(s3_interface.BUCKET, user.username, path)
return Response(data)
"""
upload file
"""
def post(self, request, path="/", format=None):
# TODO file upload
return Response({})
# file upload
# upload to server
file_serializer = FileSerializer(data=request.data)
if file_serializer.is_valid():
file_serializer.save()
# upload to s3
file_path = '.' + file_serializer.data.get('file')
user = request.user
data = s3_interface.upload_file(s3_interface.BUCKET, user.username, file_path, path+file_path.split('/')[-1])
# TODO upload check
# TODO remove local file
return Response(file_serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
"""
make directory
"""
def put(self, request, path="/", format=None):
user = request.user
data = s3_interface.make_directory(s3_interface.BUCKET, user.username, path)
return Response(data, status=status.HTTP_201_CREATED)
class FileDetail(APIView):
"""
Retrieve, update or delete a file instance.
Download or delete a file instance.
"""
# def get_object(self, pk):
# try:
# return File.objects.get(pk=pk)
# except File.DoesNotExist:
# raise Http404
def get(self, request, path="/", format=None):
# file = self.get_object(pk)
# serializer = FileSerializer(file)
# return Response(serializer.data, status=status.HTTP_200_OK)
# TODO
return
def put(self, request, path="/", format=None):
# file = self.get_object(pk)
# serializer = FileSerializer(file, data=request.data)
# if serializer.is_valid():
# serializer.save()
# return Response(serializer.data, status=status.HTTP_204_NO_CONTENT)
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
# TODO
return
# download file from s3
file = 'media/'+path.split('/')[-1]
user = request.user
s3_interface.download_file(s3_interface.BUCKET, user.username, file, path)
# TODO error
return Response({'file': file})
def delete(self, request, path="/", format=None):
result = s3_interface.delete_path(s3_interface.BUCKET, 'test1', path)
user = request.user
result = s3_interface.delete_path(s3_interface.BUCKET, user.username, path)
return Response(result)
class FileCopyMove(APIView):
"""
Download or delete a file instance.
"""
#TODO is folder move, copy well?
# move
def post(self, request, old_path, new_path, format=None):
user = request.user
if request.data.get('method') == 'mv':
s3_interface.move_file(s3_interface.BUCKET, user.username, old_path, new_path)
elif request.data.get('method') == 'cp':
s3_interface.copy_file(s3_interface.BUCKET, user.username, old_path, new_path)
else:
return Response({'stats': 'bad_request'}, status=status.HTTP_400_BAD_REQUEST)
return Response({'old_path': old_path, 'new_path': new_path})
......
<html>
<head>
<meta charset="utf-8">
<title>s3direct</title>
{{ form.media }}
</head>
<body>
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
</form>
</body>
</html>
\ No newline at end of file