[DEV] better interface
This commit is contained in:
parent
aff5e71cc5
commit
b7719edccf
@ -1,26 +1,29 @@
|
||||
FROM python:alpine
|
||||
FROM python:alpine3.6
|
||||
|
||||
RUN pip install --upgrade pip
|
||||
RUN apk update \
|
||||
&& apk add build-base
|
||||
|
||||
RUN pip install sanic
|
||||
RUN pip3 install --upgrade pip
|
||||
|
||||
RUN pip install sanic-cors
|
||||
RUN pip3 install sanic
|
||||
|
||||
RUN pip install sanic-simple-swagger
|
||||
RUN pip3 install sanic-cors
|
||||
|
||||
RUN pip install python-dateutil
|
||||
RUN pip3 install sanic-simple-swagger
|
||||
|
||||
RUN pip install realog
|
||||
RUN pip3 install python-dateutil
|
||||
|
||||
RUN pip install python-magic
|
||||
RUN pip3 install realog
|
||||
|
||||
RUN pip install pymediainfo
|
||||
RUN pip3 install python-magic
|
||||
|
||||
RUN pip3 install pymediainfo
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
ADD src /application/
|
||||
WORKDIR /application/
|
||||
CMD ["python", "-u", "./app_video.py"]
|
||||
CMD ["python3", "-u", "./app_video.py"]
|
||||
|
||||
|
||||
|
||||
|
@ -7,4 +7,6 @@ services:
|
||||
container_name: video_rest_api
|
||||
ports:
|
||||
- 15080:80
|
||||
volumes:
|
||||
- ./data:/application/data
|
||||
|
||||
|
@ -64,6 +64,16 @@ def add(_app, _name_api):
|
||||
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
|
||||
|
||||
|
||||
@elem_blueprint.get('/' + _name_api + '/exist/<sha512:string>', strict_slashes=True)
|
||||
@doc.summary("check resource existance")
|
||||
@doc.description("simply check if the resource is already uploaded.")
|
||||
@doc.produces(content_type='application/json')
|
||||
async def check_existance(request, sha512):
|
||||
value = data_global_elements.get_interface(_name_api).gets_where(select=[["==", "sha512", sha512]], filter=["id"])
|
||||
if value != None:
|
||||
return response.json({"found":True})
|
||||
raise ServerError("No data found", status_code=404)
|
||||
|
||||
|
||||
@elem_blueprint.post('/' + _name_api, strict_slashes=True, stream=True)
|
||||
@doc.summary("send new file data")
|
||||
@ -85,6 +95,7 @@ def add(_app, _name_api):
|
||||
file_stream = open(temporary_file,"wb")
|
||||
sha1 = hashlib.sha512()
|
||||
while True:
|
||||
debug.warning("ploufffff " + str(dir(_request.stream)))
|
||||
body = await _request.stream.read()
|
||||
if body is None:
|
||||
debug.warning("empty body");
|
||||
@ -140,22 +151,21 @@ def add(_app, _name_api):
|
||||
await _response.write(json.dumps(return_bdd, sort_keys=True, indent=4))
|
||||
return response.stream(streaming, content_type='application/json')
|
||||
|
||||
@elem_blueprint.get('/' + _name_api + '/<id:string>', strict_slashes=True)
|
||||
@elem_blueprint.get('/' + _name_api + '/<id:int>', strict_slashes=True)
|
||||
@doc.summary("get a specific resource")
|
||||
@doc.description("Get a resource with all the needed datas ... It permeit seek for video stream.")
|
||||
@doc.produces(content_type='application/json')
|
||||
async def retrive(request, id):
|
||||
debug.warning("Request data media 2 : " + id);
|
||||
debug.warning("Request data media 2 : " + str(id));
|
||||
"""
|
||||
if id[-4:] == ".mp4":
|
||||
id = id[:-4]
|
||||
if id[-4:] == ".mkv":
|
||||
id = id[:-4]
|
||||
if id[-4:] == ".avi":
|
||||
id = id[:-4]
|
||||
if id[-4:] == ".ts":
|
||||
id = id[:-3]
|
||||
filename = os.path.join(_app.config['REST_MEDIA_DATA'], id, "video")
|
||||
"""
|
||||
filename = os.path.join(_app.config['REST_MEDIA_DATA'], str(id), "video")
|
||||
value = data_global_elements.get_interface(_name_api).get(id)
|
||||
debug.info("plouuuuuuf " + str(value))
|
||||
headers = {
|
||||
'Content-Type': value["mime_type"],
|
||||
'Accept-Ranges': 'Accept-Ranges: bytes'
|
||||
|
@ -59,7 +59,7 @@ if "REST_MEDIA_DATA" not in app.config.keys():
|
||||
if "REST_DATA" not in app.config.keys():
|
||||
app.config['REST_DATA'] = "data"
|
||||
if "REST_HOST" not in app.config.keys():
|
||||
app.config['REST_HOST'] = "localhost"
|
||||
app.config['REST_HOST'] = "0.0.0.0"
|
||||
if "REST_PORT" not in app.config.keys():
|
||||
app.config['REST_PORT'] = "80"
|
||||
|
||||
|
@ -34,6 +34,7 @@ def save_all():
|
||||
if system_counter <= 10:
|
||||
return
|
||||
system_counter = 0
|
||||
print(time.ctime())
|
||||
for elem in interfaces.keys():
|
||||
if system_stop == True:
|
||||
return
|
||||
@ -46,7 +47,6 @@ def save_all_before_stop():
|
||||
interfaces[elem].check_save()
|
||||
|
||||
def check_save():
|
||||
print(time.ctime())
|
||||
save_all()
|
||||
if system_stop == True:
|
||||
return
|
||||
|
@ -132,11 +132,14 @@ class DataInterface():
|
||||
return self.filter_object_values(tmp_list, filter);
|
||||
|
||||
def get(self, _id):
|
||||
if type(_id) != int:
|
||||
debug.warning("get wrong input type...")
|
||||
debug.info("get " + self.name + ": " + str(_id))
|
||||
for elem in self.bdd:
|
||||
if 'id' in elem.keys() \
|
||||
and elem["id"] == _id:
|
||||
return elem
|
||||
debug.warning("not found element: " + str(len(self.bdd)))
|
||||
return None
|
||||
|
||||
def delete(self, _id):
|
||||
|
@ -10,6 +10,7 @@
|
||||
import os
|
||||
import copy
|
||||
import sys
|
||||
import datetime
|
||||
import hashlib
|
||||
import requests # pip install requests
|
||||
import realog.debug as debug
|
||||
@ -23,6 +24,7 @@ class upload_in_chunks(object):
|
||||
self.filename = filename
|
||||
self.chunksize = chunksize
|
||||
self.totalsize = os.path.getsize(filename)
|
||||
self.start_time = datetime.datetime.utcnow()
|
||||
self.readsofar = 0
|
||||
|
||||
def __iter__(self):
|
||||
@ -34,7 +36,8 @@ class upload_in_chunks(object):
|
||||
break
|
||||
self.readsofar += len(data)
|
||||
percent = self.readsofar * 1e2 / self.totalsize
|
||||
sys.stderr.write("\rSendfing data: {percent:3.0f}% {size:14.0f} / {total_size}".format(percent=percent, size=self.readsofar, total_size=self.totalsize))
|
||||
since_time = datetime.datetime.utcnow() - self.start_time
|
||||
sys.stderr.write("\rSending data: {percent:3.0f}% {size:14.0f} / {total_size} {time}".format(percent=percent, size=self.readsofar, total_size=self.totalsize), time=since_time)
|
||||
yield data
|
||||
|
||||
def __len__(self):
|
||||
@ -410,7 +413,7 @@ def push_video_file(_path, _basic_key={}):
|
||||
debug.info("pared meta data: " + json.dumps(_basic_key, sort_keys=True, indent=4))
|
||||
data_model = {
|
||||
"type_id": _basic_key["type"],
|
||||
"sha512": result_send_data_json["sha512"],
|
||||
"data_id": result_send_data_json["id"],
|
||||
#"group_id": int,
|
||||
"name": _basic_key["title"],
|
||||
# number of second
|
||||
|
@ -57,7 +57,7 @@ export class ElementVideoComponent implements OnInit {
|
||||
self.time = response.time;
|
||||
self.generated_name = response.generated_name;
|
||||
if (self.data_id != -1) {
|
||||
self.video_source = "http://localhost:15080/data/" + self.data_id + ".mp4";
|
||||
self.video_source = "http://localhost:15080/data/" + self.data_id;
|
||||
self.video_enable = true;
|
||||
} else {
|
||||
self.video_source = "";
|
||||
|
@ -58,7 +58,7 @@ export class VideoDetailComponent implements OnInit {
|
||||
self.time = response.time;
|
||||
self.generated_name = response.generated_name;
|
||||
if (self.data_id != -1) {
|
||||
self.video_source = "http://localhost:15080/data/" + self.data_id + ".mp4";
|
||||
self.video_source = "http://localhost:15080/data/" + self.data_id;
|
||||
} else {
|
||||
self.video_source = "";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user