Skip to content

Commit

Permalink
Merge github.com:myblt/myblt-website
Browse files Browse the repository at this point in the history
Conflicts:
	myblt.py
  • Loading branch information
S0yKaf committed Aug 18, 2015
2 parents 35bf078 + efaa31c commit 02d1222
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Everyone can see files but only members can upload new files.

##### Create a virtualenv

`virtualenv myblt`
`virtualenv env`

##### Active the virtualenv in the current shell

`. myblt/bin/activate`
`. env/bin/activate`

`pip install -r requirements.txt`

Expand Down
4 changes: 3 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"angular": "~1.3.15",
"angular-route": "~1.3.15",
"bootswatch-dist": "lumen",
"angular-bootstrap": "~0.13.0",
"ng-file-upload": "~5.0.9",
"angular-cookies": "1.3.16"
"angular-cookies": "1.3.16",
"angular-sanitize": "1.3.16"
}
}
6 changes: 6 additions & 0 deletions config/default_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DEBUG = True
UPLOAD_FOLDER = '/home/kiniamaro/uploads'
API_URL = 'http://a.maro.xyz/'
IS_PRIVATE = False
DOUBLE_EXTS = ['tar']
DATABASE_URI = 'sqlite:////tmp/test.db'
5 changes: 5 additions & 0 deletions config/example_prod_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DEBUG = False
UPLOAD_FOLDER = '/tmp/uploads'
API_URL = 'http://a.myb.lt/'
IS_PRIVATE = False
DATABASE_URI = 'mysql://myblt@localhost/myblt'
19 changes: 12 additions & 7 deletions database.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm import scoped_session, sessionmaker

engine = create_engine('sqlite:////tmp/test.db', convert_unicode=True)
#engine = create_engine('mysql://myblt@localhost/myblt', convert_unicode=True)
from sqlalchemy.orm import scoped_session, create_session

engine = None
metadata = MetaData()
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))

db_session = scoped_session(
lambda: create_session(autocommit=False, autoflush=False, bind=engine))

def init_engine(uri):
global engine
engine = create_engine(uri, convert_unicode=True)
return engine

def init_db():
global engine
metadata.create_all(bind=engine)
18 changes: 11 additions & 7 deletions myblt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
import string
import random
import uuid
import sys

from flask import Flask, request, send_from_directory, jsonify, redirect
from database import db_session, init_db
from database import db_session, init_db, init_engine

from models import Upload, User

app = Flask(__name__)
app.debug = True
app.config['UPLOAD_FOLDER'] = '/home/kiniamaro/uploads/'
app.config['API_URL'] = 'http://a.maro.xyz/'
app.config['IS_PRIVATE'] = False
app.config['DOUBLE_EXTS'] = ['tar']


def hash_exists(hash):
return Upload.query.filter(Upload.hash == hash).count() != 0
Expand Down Expand Up @@ -201,5 +197,13 @@ def shutdown_session(exception=None):
db_session.remove()

if __name__ == "__main__":
app.config.from_pyfile('config/default_config.py')

if len(sys.argv) == 2:
conf = sys.argv[1]
print('loading additional config ' + conf)
app.config.from_pyfile('config/' + conf + '_config.py')

init_engine(app.config['DATABASE_URI'])
init_db()
app.run()
11 changes: 10 additions & 1 deletion public/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
var app = angular.module('myblt', ['ngRoute', 'ngFileUpload', 'ngCookies', 'app.controllers.Index', 'app.controllers.Admin', 'app.controllers.Login'])
var app = angular.module('myblt', [
'ngRoute',
'ngFileUpload',
'ngCookies',
'ui.bootstrap',
'ngSanitize',
'app.controllers.Index',
'app.controllers.Admin',
'app.controllers.Login',
])

app.config(['$routeProvider', '$httpProvider', function($routeProvider) {
$routeProvider
Expand Down
4 changes: 4 additions & 0 deletions public/assets/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
.dragover {
border: 5px dashed blue;
}

.alerts {
margin-top: 15px;
}
24 changes: 23 additions & 1 deletion public/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
var controllers = angular.module('app.controllers.Index', ['ngFileUpload', 'ngCookies']);

controllers.controller('Index', function ($scope, $http, $cookies, $location, Upload) {
controllers.controller('Index', function ($scope, $http, $cookies, $location, $sce, Upload) {

$scope.alerts = [];
$scope.closeAlert = function(index) {
$scope.alerts.splice(index, 1);
};

$scope.upload = function (file) {
delete $scope.uploadSuccess;
Expand All @@ -12,6 +17,23 @@ controllers.controller('Index', function ($scope, $http, $cookies, $location, Up
$scope.progress = parseInt(100.0 * evt.loaded / evt.total);
}).success(function (data, status, headers, config) {
$scope.uploadSuccess = {filename: file[0].name, short_url: data.short_url};
var msg = file[0].name + ' uploaded to <a style="color: #314F00" href="' + data.short_url + '">'+data.short_url+'</a>';
var trusted = $scope.thisCanBeusedInsideNgBindHtml = $sce.trustAsHtml(msg);
var alert = {
msg: trusted,
type: 'success'};
console.log(alert);
$scope.alerts.push(alert);

delete $scope.file;
delete $scope.progress;
}).error(function (data, status, headers, config) {
console.log(status);
if (status == 413) {
$scope.alerts.push({msg: 'Your file is too big !', type: 'danger'});
} else {
$scope.alerts.push({msg: 'An error occurred while uploading your file.', type: 'danger'});
}
delete $scope.file;
delete $scope.progress;
});
Expand Down
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/bootswatch-dist/js/bootstrap.min.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
<script src="bower_components/angular-route/angular-route.min.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/ng-file-upload/ng-file-upload.min.js"></script>
<script src="bower_components/ng-file-upload/ng-file-upload-shim.min.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
Expand Down
24 changes: 16 additions & 8 deletions public/partials/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@
<div class="jumbotron jumbotron-home">
<h1>Maro.xyz</h1>
</div>

<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="col-md-6 col-md-offset-3">
<div class="drop-box" ngf-drag-over-class="dragover" ngf-select ngf-drop ng-model="file">Select file or drop here</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p ng-show="file" class="text-info text-center">Ready to upload {{file[0].name}}</p>
<p ng-show="file && file.length > 0" class="text-info text-center">Ready to upload {{file[0].name}}</p>
</div>
</div>
<div class="row" ng-show="file">
<div class="row" ng-show="file && file.length > 0">
<div class="col-md-12">
<button class="btn btn-info btn-lg center-block" ng-click="upload(file)">Upload now</button>
</div>
</div>
<div class="row" ng-show="uploadSuccess && !file">
<div class="col-md-12">
<p class="text-success text-center">
{{uploadSuccess.filename}} uploaded to <a ng-href="{{uploadSuccess.short_url}}">{{uploadSuccess.short_url}}</a>
</p>

<div class="row" ng-show="progress">
<div class="progress">
<div class="progress-bar" style="width: {{progress}}%;"></div>
</div>
</div>

<div class="row alerts">
<div class="col-md-8 col-md-offset-2">
<alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">
<span ng-bind-html="alert.msg"></span>
</alert>
</div>
</div>
<div ngf-no-file-drop>File Drag/Drop is not supported for this browser</div>
Expand Down

0 comments on commit 02d1222

Please sign in to comment.