Skip to content

Commit

Permalink
feat
Browse files Browse the repository at this point in the history
  • Loading branch information
elblogbruno committed Jul 30, 2021
1 parent 91cf3ac commit 7d63485
Show file tree
Hide file tree
Showing 96 changed files with 443 additions and 79 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.idea
*py[cod]
logs/log*
*avi
*.avi
*.sqlite
*.jpg
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Users\\elblo\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe"
}
4 changes: 3 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from controller import create_app
from flask_sqlalchemy import SQLAlchemy
import db
from controller.models.models import Wanderpi

app = create_app('dev')
db = SQLAlchemy(app)

if __name__ == '__main__':
#app.run(threaded=True, host="0.0.0.0")
db.Base.metadata.create_all(db.engine)
app.run(threaded=True, host="0.0.0.0", ssl_context='adhoc')

4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

UPLOAD_FOLDER = os.getcwd()+'/uploads/'
STATIC_FOLDER = os.getcwd()+'/controller/static/'
VIDEOS_FOLDER = os.getcwd()+'/controller/static/videos'


class Config:
# 调试模式
Expand All @@ -19,8 +21,6 @@ class DevelopmentConfig(Config):
DEBUG = True
LOG_LEVEL = logging.DEBUG
UPLOAD_FOLDER = UPLOAD_FOLDER
SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:manresa21@localhost:5432/wanderpi_db_test'
SQLALCHEMY_TRACK_MODIFICATIONS = False

class ProductionConfig(Config):
# 上线配置
Expand Down
38 changes: 26 additions & 12 deletions controller/models/models.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
from werkzeug.security import generate_password_hash, check_password_hash
import db
from sqlalchemy import Column, Integer, String, Float, DateTime, Text
from datetime import datetime

class Wanderpi(db.Model):
class Wanderpi(db.Base):
__tablename__ = 'video'
id = db.Column(db.String(256), primary_key=True)
name = db.Column(db.String(256), nullable=False)
lat = db.Column(db.String(256), nullable=False)
long = db.Column(db.String(256), nullable=False)

id = Column(String(256), primary_key=True)
name = Column(String(256), nullable=False)
lat = Column(String(256), nullable=False)
long = Column(String(256), nullable=False)
thumbnail_url = Column(String(256), nullable=False)
created_date = Column(DateTime, default=datetime.utcnow)


def __repr__(self):
return f'<User {self.id}>'

def set_id(self, id):
self.id = id


def set_name(self, id):
self.id = id

def save(self):
if not self.id:
db.session.add(self)
db.session.add(self)
db.session.commit()


@staticmethod
def delete(id):
db.session.query(Wanderpi).filter(Wanderpi.id == id).delete()
db.session.commit()
return True


@staticmethod
def get_by_id(id):
return Wanderpi.query.get(id)
return db.session.query(Wanderpi).get(id)

@staticmethod
def get_all():
return Wanderpi.query.all()
return db.session.query(Wanderpi).all()
38 changes: 33 additions & 5 deletions controller/modules/home/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from app import Wanderpi
from os import name
from config import UPLOAD_FOLDER
from config import VIDEOS_FOLDER
from flask import json, session, render_template, redirect, url_for, Response,request, jsonify,send_from_directory
from controller.modules.home import home_blu
from controller.utils.camera import VideoCamera
from controller.models.models import Wanderpi


video_camera_ids = [{"deviceId" : 0, "deviceLabel" : "Webcam"}, {"deviceId" : 1, "deviceLabel" : "Webcam1"}]

Expand All @@ -19,7 +20,25 @@ def index():
return redirect(url_for("user.login"))

wanderpis = Wanderpi.get_all()
return render_template("test.html", wanderpis=wanderpis)
return render_template("index.html", wanderpis=wanderpis)

@home_blu.route('/delete_video/<string:id>')
def delete_video(id):
print(id)
Wanderpi.delete(id)
return redirect("/", code=302)


@home_blu.route('/<path:id>')
def single_video(id):
# 模板渲染
username = session.get("username")
if not username:
session["initialized"] = False
return redirect(url_for("user.login"))

wanderpi = Wanderpi.get_by_id(id)
return render_template("single-video-view.html", video=wanderpi)

# 主页
@home_blu.route('/record')
Expand Down Expand Up @@ -103,7 +122,7 @@ def record_status():

@home_blu.route('/uploads/<path:filename>', methods=['GET', 'POST'])
def download_file(filename):
return send_from_directory(directory=UPLOAD_FOLDER, path=filename, as_attachment=True)
return send_from_directory(VIDEOS_FOLDER, filename, as_attachment=True)


@home_blu.route('/get_available_video_sources', methods=['GET', 'POST'])
Expand All @@ -114,7 +133,16 @@ def get_available_video_sources(): #todo get available video sources from databa
def save_video(video_id): #todo get available video sources from database
print("Saving video {0}".format(video_id))

wanderpi = Wanderpi(id=video_id, name="a", lat="a", long="a")
name = request.args.get('name', default=video_id)
if name == "":
name = video_id
lat_coord = request.args.get('lat')
long_coord = request.args.get('long')
thumbnail_url = "thumbnail-%s.jpg" % str(video_id)

print(name, lat_coord, long_coord, thumbnail_url)

wanderpi = Wanderpi(id=video_id, name=name, lat=lat_coord, long=long_coord, thumbnail_url=thumbnail_url)
wanderpi.save()

return jsonify(devices = video_camera_ids)
Expand Down
Binary file not shown.
14 changes: 14 additions & 0 deletions controller/static/css/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.camera-view-responsive
{
border-radius: 5px;
margin-bottom: 12px;
}

body {
background-color: #6F6F6F;
}

.change-my-color {
width: 200px;
}

4 changes: 4 additions & 0 deletions controller/static/css/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$light: #dddddd;
$dark: #000;

@import "bootstrap";
3 changes: 2 additions & 1 deletion controller/static/css/recording-screen-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@
width: 100% !important;
height: 100% !important;
border-radius: 5px;
}
}

Binary file added controller/static/images/add-more-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions controller/static/images/add-more-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions controller/static/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function deleteVideo(id){
console.log(id);
}

function shareVideo(id){

if (navigator.share) {
navigator.share({
title: 'WebShare API Demo',
url: 'https://codepen.io/ayoisaiah/pen/YbNazJ'
}).then(() => {
console.log('Thanks for sharing!');
})
.catch(console.error);
} else {
// fallback
}
}
19 changes: 17 additions & 2 deletions controller/static/recorder.js → controller/static/js/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ downloadLink.style.display = "none";
buttonStop.disabled = true;
statusBadgeContainer.style.display = "none";

var lat = 0;
var long = 0;

function initializeDropdown() {

Expand Down Expand Up @@ -82,7 +84,18 @@ saveButtonModal.onclick = function () {
window.location.href = "/";
}
}
xhr.open("POST", "/save_video/" + saveButton.value + "/");

var name_input = document.getElementById("name_input");

var base_url = window.location.origin;
var url = new URL(base_url+"/save_video/"+ saveButton.value+'/');

url.searchParams.append('name', name_input.value);
url.searchParams.append('lat', lat);
url.searchParams.append('long', long);


xhr.open("POST", url.toString());
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send();
};
Expand All @@ -104,7 +117,7 @@ buttonStop.onclick = function () {
saveButton.value = video_id;
downloadLink.style.display = "inline";
downloadLink.onclick = function () {
window.location.href = "/uploads/" + video_id;
window.location.href = "/uploads/" + video_id + '.mp4';
}
}
}
Expand Down Expand Up @@ -140,6 +153,8 @@ function initializeMapAndLocator()
{
console.log(e);
var radius = e.accuracy / 2;
lat = e.latitude;
long = e.longitude;
L.marker(e.latlng).addTo(map).bindPopup("You are within " + radius + " meters from this point").openPopup();
L.circle(e.latlng, radius).addTo(map);
}
Expand Down
14 changes: 14 additions & 0 deletions controller/static/js/single-video-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

function showPosition(lat, long) {
var gps = document.getElementById("gps_text");

gps.innerHTML = lat + " " + long;
var map = L.map('map-container-google-1');

map.setView([lat,long], 13);

googleStreets = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3']
}).addTo(map);
}
Binary file added controller/static/no_videos_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 7d63485

Please sign in to comment.