1
0
mirror of https://github.com/Foltik/Shimapan synced 2025-01-23 07:10:36 -05:00
shimapan/public/js/shimapan.min.js
2017-10-20 16:46:14 -04:00

1 line
2.9 KiB
JavaScript

(angular=require("angular")).module("ApiSvc",[]).service("ApiService",["$http","$window",function(e,n){this.getKey=function(n,o){e({method:"GET",url:"/api/keys/get",params:{identifier:n}}).then(function(e){o(e.data)})},this.getAll=function(n){e({method:"GET",url:"/api/keys/get"}).then(function(e){n(e.data)})}}]),(angular=require("angular")).module("AuthSvc",[]).service("AuthService",["$http","$window",function(e,n){this.login=function(o){return e({method:"POST",url:"/api/auth/login",headers:{"Content-Type":"application/x-www-form-urlencoded"},transformRequest:function(e){var n=[];for(var o in e)n.push(encodeURIComponent(o)+"="+encodeURIComponent(e[o]));return n.join("&")},data:o}).then(function(e){if(401===e.status)return!1;n.location.href="/home"})},this.logout=function(){e({method:"GET",url:"/api/auth/logout"}).then(function(){n.location.href="/"})},this.register=function(o){return e({method:"POST",url:"/api/auth/register",headers:{"Content-Type":"application/x-www-form-urlencoded"},transformRequest:function(e){var n=[];for(var o in e)n.push(encodeURIComponent(o)+"="+encodeURIComponent(e[o]));return n.join("&")},data:o}).then(function(e){if(401===e.status)return!1;n.location.href="/home"})},this.currentUser=function(n){return e({method:"GET",url:"/api/auth/session",headers:{"Content-Type":"application/json"}}).then(function(e){n(e.data)})}}]);var angular=require("angular"),ngFileUpload=require("ng-file-upload"),ngclipboard=require("ngclipboard"),app=angular.module("shimapan",["ngFileUpload","ngclipboard","UploadComp","RegisterComp","LoginComp"]);(angular=require("angular")).module("LoginComp",["AuthSvc"]).component("loginComponent",{templateUrl:"/views/shimapan/login-form.html",controller:["$scope","AuthService",function(e,n){e.login=function(){n.login({username:e.username,password:e.password})}}]}),(angular=require("angular")).module("RegisterComp",["AuthSvc"]).component("registerComponent",{templateUrl:"/views/shimapan/register-form.html",controller:["$scope","AuthService",function(e,n){e.register=function(){n.register({username:e.username,password:e.password,invite:e.invite})}}]}),(angular=require("angular")).module("UploadComp",["ngFileUpload","AuthSvc"]).component("uploadComponent",{templateUrl:"/views/shimapan/upload-form.html",controller:["$scope","Upload","$timeout","AuthService",function(e,n,o,r){e.errToString=function(e){return"maxSize"===e?"File too large.":e},e.uploadFiles=function(r,t){e.files=e.files?e.files.concat(r):r,e.errorFiles=e.errorFiles?e.errorFiles.concat(t):t,angular.forEach(r,function(r){r.upload=n.upload({url:"/api/upload",method:"POST",file:r}),r.upload.then(function(e){o(function(){r.result=e.data})},function(n){if(200!==n.status){401===n.status?r.$error="Invalid authorization token":403===n.status?r.$error="Forbidden":r.$error="Unknown error "+n.status;var o=e.files.indexOf(r);e.errorFiles.push(r),e.files.splice(o,1)}},function(e){r.progress=Math.floor(Math.min(100,100*e.loaded/e.total))})})}}],controllerAs:"vm"});