mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-09-12 23:11:38 +08:00
添加Metronic(作为LFS)
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
application: jquery-file-upload
|
||||
version: 2
|
||||
runtime: go
|
||||
api_version: go1
|
||||
|
||||
handlers:
|
||||
- url: /(favicon\.ico|robots\.txt)
|
||||
static_files: static/\1
|
||||
upload: static/(.*)
|
||||
expiration: '1d'
|
||||
- url: /.*
|
||||
script: _go_app
|
@@ -0,0 +1,296 @@
|
||||
/*
|
||||
* jQuery File Upload Plugin GAE Go Example 3.1.1
|
||||
* https://github.com/blueimp/jQuery-File-Upload
|
||||
*
|
||||
* Copyright 2011, Sebastian Tschan
|
||||
* https://blueimp.net
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"appengine"
|
||||
"appengine/blobstore"
|
||||
"appengine/image"
|
||||
"appengine/taskqueue"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
WEBSITE = "http://blueimp.github.io/jQuery-File-Upload/"
|
||||
MIN_FILE_SIZE = 1 // bytes
|
||||
MAX_FILE_SIZE = 5000000 // bytes
|
||||
IMAGE_TYPES = "image/(gif|p?jpeg|(x-)?png)"
|
||||
ACCEPT_FILE_TYPES = IMAGE_TYPES
|
||||
EXPIRATION_TIME = 300 // seconds
|
||||
THUMBNAIL_PARAM = "=s80"
|
||||
)
|
||||
|
||||
var (
|
||||
imageTypes = regexp.MustCompile(IMAGE_TYPES)
|
||||
acceptFileTypes = regexp.MustCompile(ACCEPT_FILE_TYPES)
|
||||
)
|
||||
|
||||
type FileInfo struct {
|
||||
Key appengine.BlobKey `json:"-"`
|
||||
Url string `json:"url,omitempty"`
|
||||
ThumbnailUrl string `json:"thumbnailUrl,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Size int64 `json:"size"`
|
||||
Error string `json:"error,omitempty"`
|
||||
DeleteUrl string `json:"deleteUrl,omitempty"`
|
||||
DeleteType string `json:"deleteType,omitempty"`
|
||||
}
|
||||
|
||||
func (fi *FileInfo) ValidateType() (valid bool) {
|
||||
if acceptFileTypes.MatchString(fi.Type) {
|
||||
return true
|
||||
}
|
||||
fi.Error = "Filetype not allowed"
|
||||
return false
|
||||
}
|
||||
|
||||
func (fi *FileInfo) ValidateSize() (valid bool) {
|
||||
if fi.Size < MIN_FILE_SIZE {
|
||||
fi.Error = "File is too small"
|
||||
} else if fi.Size > MAX_FILE_SIZE {
|
||||
fi.Error = "File is too big"
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (fi *FileInfo) CreateUrls(r *http.Request, c appengine.Context) {
|
||||
u := &url.URL{
|
||||
Scheme: r.URL.Scheme,
|
||||
Host: appengine.DefaultVersionHostname(c),
|
||||
Path: "/",
|
||||
}
|
||||
uString := u.String()
|
||||
fi.Url = uString + escape(string(fi.Key)) + "/" +
|
||||
escape(string(fi.Name))
|
||||
fi.DeleteUrl = fi.Url + "?delete=true"
|
||||
fi.DeleteType = "DELETE"
|
||||
if imageTypes.MatchString(fi.Type) {
|
||||
servingUrl, err := image.ServingURL(
|
||||
c,
|
||||
fi.Key,
|
||||
&image.ServingURLOptions{
|
||||
Secure: strings.HasSuffix(u.Scheme, "s"),
|
||||
Size: 0,
|
||||
Crop: false,
|
||||
},
|
||||
)
|
||||
check(err)
|
||||
fi.ThumbnailUrl = servingUrl.String() + THUMBNAIL_PARAM
|
||||
}
|
||||
}
|
||||
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func escape(s string) string {
|
||||
return strings.Replace(url.QueryEscape(s), "+", "%20", -1)
|
||||
}
|
||||
|
||||
func delayedDelete(c appengine.Context, fi *FileInfo) {
|
||||
if key := string(fi.Key); key != "" {
|
||||
task := &taskqueue.Task{
|
||||
Path: "/" + escape(key) + "/-",
|
||||
Method: "DELETE",
|
||||
Delay: time.Duration(EXPIRATION_TIME) * time.Second,
|
||||
}
|
||||
taskqueue.Add(c, task, "")
|
||||
}
|
||||
}
|
||||
|
||||
func handleUpload(r *http.Request, p *multipart.Part) (fi *FileInfo) {
|
||||
fi = &FileInfo{
|
||||
Name: p.FileName(),
|
||||
Type: p.Header.Get("Content-Type"),
|
||||
}
|
||||
if !fi.ValidateType() {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
log.Println(rec)
|
||||
fi.Error = rec.(error).Error()
|
||||
}
|
||||
}()
|
||||
lr := &io.LimitedReader{R: p, N: MAX_FILE_SIZE + 1}
|
||||
context := appengine.NewContext(r)
|
||||
w, err := blobstore.Create(context, fi.Type)
|
||||
defer func() {
|
||||
w.Close()
|
||||
fi.Size = MAX_FILE_SIZE + 1 - lr.N
|
||||
fi.Key, err = w.Key()
|
||||
check(err)
|
||||
if !fi.ValidateSize() {
|
||||
err := blobstore.Delete(context, fi.Key)
|
||||
check(err)
|
||||
return
|
||||
}
|
||||
delayedDelete(context, fi)
|
||||
fi.CreateUrls(r, context)
|
||||
}()
|
||||
check(err)
|
||||
_, err = io.Copy(w, lr)
|
||||
return
|
||||
}
|
||||
|
||||
func getFormValue(p *multipart.Part) string {
|
||||
var b bytes.Buffer
|
||||
io.CopyN(&b, p, int64(1<<20)) // Copy max: 1 MiB
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func handleUploads(r *http.Request) (fileInfos []*FileInfo) {
|
||||
fileInfos = make([]*FileInfo, 0)
|
||||
mr, err := r.MultipartReader()
|
||||
check(err)
|
||||
r.Form, err = url.ParseQuery(r.URL.RawQuery)
|
||||
check(err)
|
||||
part, err := mr.NextPart()
|
||||
for err == nil {
|
||||
if name := part.FormName(); name != "" {
|
||||
if part.FileName() != "" {
|
||||
fileInfos = append(fileInfos, handleUpload(r, part))
|
||||
} else {
|
||||
r.Form[name] = append(r.Form[name], getFormValue(part))
|
||||
}
|
||||
}
|
||||
part, err = mr.NextPart()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func get(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/" {
|
||||
http.Redirect(w, r, WEBSITE, http.StatusFound)
|
||||
return
|
||||
}
|
||||
parts := strings.Split(r.URL.Path, "/")
|
||||
if len(parts) == 3 {
|
||||
if key := parts[1]; key != "" {
|
||||
blobKey := appengine.BlobKey(key)
|
||||
bi, err := blobstore.Stat(appengine.NewContext(r), blobKey)
|
||||
if err == nil {
|
||||
w.Header().Add("X-Content-Type-Options", "nosniff")
|
||||
if !imageTypes.MatchString(bi.ContentType) {
|
||||
w.Header().Add("Content-Type", "application/octet-stream")
|
||||
w.Header().Add(
|
||||
"Content-Disposition",
|
||||
fmt.Sprintf("attachment; filename=\"%s\"", parts[2]),
|
||||
)
|
||||
}
|
||||
w.Header().Add(
|
||||
"Cache-Control",
|
||||
fmt.Sprintf("public,max-age=%d", EXPIRATION_TIME),
|
||||
)
|
||||
blobstore.Send(w, blobKey)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
http.Error(w, "404 Not Found", http.StatusNotFound)
|
||||
}
|
||||
|
||||
func post(w http.ResponseWriter, r *http.Request) {
|
||||
result := make(map[string][]*FileInfo, 1)
|
||||
result["files"] = handleUploads(r)
|
||||
b, err := json.Marshal(result)
|
||||
check(err)
|
||||
if redirect := r.FormValue("redirect"); redirect != "" {
|
||||
if strings.Contains(redirect, "%s") {
|
||||
redirect = fmt.Sprintf(
|
||||
redirect,
|
||||
escape(string(b)),
|
||||
)
|
||||
}
|
||||
http.Redirect(w, r, redirect, http.StatusFound)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
jsonType := "application/json"
|
||||
if strings.Index(r.Header.Get("Accept"), jsonType) != -1 {
|
||||
w.Header().Set("Content-Type", jsonType)
|
||||
}
|
||||
fmt.Fprintln(w, string(b))
|
||||
}
|
||||
|
||||
func delete(w http.ResponseWriter, r *http.Request) {
|
||||
parts := strings.Split(r.URL.Path, "/")
|
||||
if len(parts) != 3 {
|
||||
return
|
||||
}
|
||||
result := make(map[string]bool, 1)
|
||||
if key := parts[1]; key != "" {
|
||||
c := appengine.NewContext(r)
|
||||
blobKey := appengine.BlobKey(key)
|
||||
err := blobstore.Delete(c, blobKey)
|
||||
check(err)
|
||||
err = image.DeleteServingURL(c, blobKey)
|
||||
check(err)
|
||||
result[key] = true
|
||||
}
|
||||
jsonType := "application/json"
|
||||
if strings.Index(r.Header.Get("Accept"), jsonType) != -1 {
|
||||
w.Header().Set("Content-Type", jsonType)
|
||||
}
|
||||
b, err := json.Marshal(result)
|
||||
check(err)
|
||||
fmt.Fprintln(w, string(b))
|
||||
}
|
||||
|
||||
func handle(w http.ResponseWriter, r *http.Request) {
|
||||
params, err := url.ParseQuery(r.URL.RawQuery)
|
||||
check(err)
|
||||
w.Header().Add("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Add(
|
||||
"Access-Control-Allow-Methods",
|
||||
"OPTIONS, HEAD, GET, POST, PUT, DELETE",
|
||||
)
|
||||
w.Header().Add(
|
||||
"Access-Control-Allow-Headers",
|
||||
"Content-Type, Content-Range, Content-Disposition",
|
||||
)
|
||||
switch r.Method {
|
||||
case "OPTIONS":
|
||||
case "HEAD":
|
||||
case "GET":
|
||||
get(w, r)
|
||||
case "POST":
|
||||
if len(params["_method"]) > 0 && params["_method"][0] == "DELETE" {
|
||||
delete(w, r)
|
||||
} else {
|
||||
post(w, r)
|
||||
}
|
||||
case "DELETE":
|
||||
delete(w, r)
|
||||
default:
|
||||
http.Error(w, "501 Not Implemented", http.StatusNotImplemented)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
http.HandleFunc("/", handle)
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Disallow:
|
@@ -0,0 +1,16 @@
|
||||
application: jquery-file-upload
|
||||
version: 1
|
||||
runtime: python27
|
||||
api_version: 1
|
||||
threadsafe: true
|
||||
|
||||
builtins:
|
||||
- deferred: on
|
||||
|
||||
handlers:
|
||||
- url: /(favicon\.ico|robots\.txt)
|
||||
static_files: static/\1
|
||||
upload: static/(.*)
|
||||
expiration: '1d'
|
||||
- url: /.*
|
||||
script: main.app
|
@@ -0,0 +1,170 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# jQuery File Upload Plugin GAE Python Example 2.1.1
|
||||
# https://github.com/blueimp/jQuery-File-Upload
|
||||
#
|
||||
# Copyright 2011, Sebastian Tschan
|
||||
# https://blueimp.net
|
||||
#
|
||||
# Licensed under the MIT license:
|
||||
# http://www.opensource.org/licenses/MIT
|
||||
#
|
||||
|
||||
from __future__ import with_statement
|
||||
from google.appengine.api import files, images
|
||||
from google.appengine.ext import blobstore, deferred
|
||||
from google.appengine.ext.webapp import blobstore_handlers
|
||||
import json
|
||||
import re
|
||||
import urllib
|
||||
import webapp2
|
||||
|
||||
WEBSITE = 'http://blueimp.github.io/jQuery-File-Upload/'
|
||||
MIN_FILE_SIZE = 1 # bytes
|
||||
MAX_FILE_SIZE = 5000000 # bytes
|
||||
IMAGE_TYPES = re.compile('image/(gif|p?jpeg|(x-)?png)')
|
||||
ACCEPT_FILE_TYPES = IMAGE_TYPES
|
||||
THUMBNAIL_MODIFICATOR = '=s80' # max width / height
|
||||
EXPIRATION_TIME = 300 # seconds
|
||||
|
||||
|
||||
def cleanup(blob_keys):
|
||||
blobstore.delete(blob_keys)
|
||||
|
||||
|
||||
class UploadHandler(webapp2.RequestHandler):
|
||||
|
||||
def initialize(self, request, response):
|
||||
super(UploadHandler, self).initialize(request, response)
|
||||
self.response.headers['Access-Control-Allow-Origin'] = '*'
|
||||
self.response.headers[
|
||||
'Access-Control-Allow-Methods'
|
||||
] = 'OPTIONS, HEAD, GET, POST, PUT, DELETE'
|
||||
self.response.headers[
|
||||
'Access-Control-Allow-Headers'
|
||||
] = 'Content-Type, Content-Range, Content-Disposition'
|
||||
|
||||
def validate(self, file):
|
||||
if file['size'] < MIN_FILE_SIZE:
|
||||
file['error'] = 'File is too small'
|
||||
elif file['size'] > MAX_FILE_SIZE:
|
||||
file['error'] = 'File is too big'
|
||||
elif not ACCEPT_FILE_TYPES.match(file['type']):
|
||||
file['error'] = 'Filetype not allowed'
|
||||
else:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_file_size(self, file):
|
||||
file.seek(0, 2) # Seek to the end of the file
|
||||
size = file.tell() # Get the position of EOF
|
||||
file.seek(0) # Reset the file position to the beginning
|
||||
return size
|
||||
|
||||
def write_blob(self, data, info):
|
||||
blob = files.blobstore.create(
|
||||
mime_type=info['type'],
|
||||
_blobinfo_uploaded_filename=info['name']
|
||||
)
|
||||
with files.open(blob, 'a') as f:
|
||||
f.write(data)
|
||||
files.finalize(blob)
|
||||
return files.blobstore.get_blob_key(blob)
|
||||
|
||||
def handle_upload(self):
|
||||
results = []
|
||||
blob_keys = []
|
||||
for name, fieldStorage in self.request.POST.items():
|
||||
if type(fieldStorage) is unicode:
|
||||
continue
|
||||
result = {}
|
||||
result['name'] = re.sub(
|
||||
r'^.*\\',
|
||||
'',
|
||||
fieldStorage.filename
|
||||
)
|
||||
result['type'] = fieldStorage.type
|
||||
result['size'] = self.get_file_size(fieldStorage.file)
|
||||
if self.validate(result):
|
||||
blob_key = str(
|
||||
self.write_blob(fieldStorage.value, result)
|
||||
)
|
||||
blob_keys.append(blob_key)
|
||||
result['deleteType'] = 'DELETE'
|
||||
result['deleteUrl'] = self.request.host_url +\
|
||||
'/?key=' + urllib.quote(blob_key, '')
|
||||
if (IMAGE_TYPES.match(result['type'])):
|
||||
try:
|
||||
result['url'] = images.get_serving_url(
|
||||
blob_key,
|
||||
secure_url=self.request.host_url.startswith(
|
||||
'https'
|
||||
)
|
||||
)
|
||||
result['thumbnailUrl'] = result['url'] +\
|
||||
THUMBNAIL_MODIFICATOR
|
||||
except: # Could not get an image serving url
|
||||
pass
|
||||
if not 'url' in result:
|
||||
result['url'] = self.request.host_url +\
|
||||
'/' + blob_key + '/' + urllib.quote(
|
||||
result['name'].encode('utf-8'), '')
|
||||
results.append(result)
|
||||
deferred.defer(
|
||||
cleanup,
|
||||
blob_keys,
|
||||
_countdown=EXPIRATION_TIME
|
||||
)
|
||||
return results
|
||||
|
||||
def options(self):
|
||||
pass
|
||||
|
||||
def head(self):
|
||||
pass
|
||||
|
||||
def get(self):
|
||||
self.redirect(WEBSITE)
|
||||
|
||||
def post(self):
|
||||
if (self.request.get('_method') == 'DELETE'):
|
||||
return self.delete()
|
||||
result = {'files': self.handle_upload()}
|
||||
s = json.dumps(result, separators=(',', ':'))
|
||||
redirect = self.request.get('redirect')
|
||||
if redirect:
|
||||
return self.redirect(str(
|
||||
redirect.replace('%s', urllib.quote(s, ''), 1)
|
||||
))
|
||||
if 'application/json' in self.request.headers.get('Accept'):
|
||||
self.response.headers['Content-Type'] = 'application/json'
|
||||
self.response.write(s)
|
||||
|
||||
def delete(self):
|
||||
key = self.request.get('key') or ''
|
||||
blobstore.delete(key)
|
||||
s = json.dumps({key: True}, separators=(',', ':'))
|
||||
if 'application/json' in self.request.headers.get('Accept'):
|
||||
self.response.headers['Content-Type'] = 'application/json'
|
||||
self.response.write(s)
|
||||
|
||||
|
||||
class DownloadHandler(blobstore_handlers.BlobstoreDownloadHandler):
|
||||
def get(self, key, filename):
|
||||
if not blobstore.get(key):
|
||||
self.error(404)
|
||||
else:
|
||||
# Prevent browsers from MIME-sniffing the content-type:
|
||||
self.response.headers['X-Content-Type-Options'] = 'nosniff'
|
||||
# Cache for the expiration time:
|
||||
self.response.headers['Cache-Control'] = 'public,max-age=%d' % EXPIRATION_TIME
|
||||
# Send the file forcing a download dialog:
|
||||
self.send_blob(key, save_as=filename, content_type='application/octet-stream')
|
||||
|
||||
app = webapp2.WSGIApplication(
|
||||
[
|
||||
('/', UploadHandler),
|
||||
('/([^/]+)/([^/]+)', DownloadHandler)
|
||||
],
|
||||
debug=True
|
||||
)
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Disallow:
|
2
frontend/static/assets/global/plugins/jquery-file-upload/server/node/.gitignore
vendored
Normal file
2
frontend/static/assets/global/plugins/jquery-file-upload/server/node/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.DS_Store
|
||||
node_modules
|
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "blueimp-file-upload-node",
|
||||
"version": "2.1.0",
|
||||
"title": "jQuery File Upload Node.js example",
|
||||
"description": "Node.js implementation example of a file upload handler for jQuery File Upload.",
|
||||
"keywords": [
|
||||
"file",
|
||||
"upload",
|
||||
"cross-domain",
|
||||
"cross-site",
|
||||
"node"
|
||||
],
|
||||
"homepage": "https://github.com/blueimp/jQuery-File-Upload",
|
||||
"author": {
|
||||
"name": "Sebastian Tschan",
|
||||
"url": "https://blueimp.net"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Sebastian Tschan",
|
||||
"url": "https://blueimp.net"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/blueimp/jQuery-File-Upload.git"
|
||||
},
|
||||
"bugs": "https://github.com/blueimp/jQuery-File-Upload/issues",
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://www.opensource.org/licenses/MIT"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"formidable": ">=1.0.11",
|
||||
"node-static": ">=0.6.5",
|
||||
"imagemagick": ">=0.1.3"
|
||||
},
|
||||
"main": "server.js"
|
||||
}
|
2
frontend/static/assets/global/plugins/jquery-file-upload/server/node/public/files/.gitignore
vendored
Normal file
2
frontend/static/assets/global/plugins/jquery-file-upload/server/node/public/files/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
292
frontend/static/assets/global/plugins/jquery-file-upload/server/node/server.js
vendored
Normal file
292
frontend/static/assets/global/plugins/jquery-file-upload/server/node/server.js
vendored
Normal file
@@ -0,0 +1,292 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
* jQuery File Upload Plugin Node.js Example 2.1.1
|
||||
* https://github.com/blueimp/jQuery-File-Upload
|
||||
*
|
||||
* Copyright 2012, Sebastian Tschan
|
||||
* https://blueimp.net
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
/* jshint nomen:false */
|
||||
/* global require, __dirname, unescape, console */
|
||||
|
||||
(function (port) {
|
||||
'use strict';
|
||||
var path = require('path'),
|
||||
fs = require('fs'),
|
||||
// Since Node 0.8, .existsSync() moved from path to fs:
|
||||
_existsSync = fs.existsSync || path.existsSync,
|
||||
formidable = require('formidable'),
|
||||
nodeStatic = require('node-static'),
|
||||
imageMagick = require('imagemagick'),
|
||||
options = {
|
||||
tmpDir: __dirname + '/tmp',
|
||||
publicDir: __dirname + '/public',
|
||||
uploadDir: __dirname + '/public/files',
|
||||
uploadUrl: '/files/',
|
||||
maxPostSize: 11000000000, // 11 GB
|
||||
minFileSize: 1,
|
||||
maxFileSize: 10000000000, // 10 GB
|
||||
acceptFileTypes: /.+/i,
|
||||
// Files not matched by this regular expression force a download dialog,
|
||||
// to prevent executing any scripts in the context of the service domain:
|
||||
inlineFileTypes: /\.(gif|jpe?g|png)$/i,
|
||||
imageTypes: /\.(gif|jpe?g|png)$/i,
|
||||
imageVersions: {
|
||||
'thumbnail': {
|
||||
width: 80,
|
||||
height: 80
|
||||
}
|
||||
},
|
||||
accessControl: {
|
||||
allowOrigin: '*',
|
||||
allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE',
|
||||
allowHeaders: 'Content-Type, Content-Range, Content-Disposition'
|
||||
},
|
||||
/* Uncomment and edit this section to provide the service via HTTPS:
|
||||
ssl: {
|
||||
key: fs.readFileSync('/Applications/XAMPP/etc/ssl.key/server.key'),
|
||||
cert: fs.readFileSync('/Applications/XAMPP/etc/ssl.crt/server.crt')
|
||||
},
|
||||
*/
|
||||
nodeStatic: {
|
||||
cache: 3600 // seconds to cache served files
|
||||
}
|
||||
},
|
||||
utf8encode = function (str) {
|
||||
return unescape(encodeURIComponent(str));
|
||||
},
|
||||
fileServer = new nodeStatic.Server(options.publicDir, options.nodeStatic),
|
||||
nameCountRegexp = /(?:(?: \(([\d]+)\))?(\.[^.]+))?$/,
|
||||
nameCountFunc = function (s, index, ext) {
|
||||
return ' (' + ((parseInt(index, 10) || 0) + 1) + ')' + (ext || '');
|
||||
},
|
||||
FileInfo = function (file) {
|
||||
this.name = file.name;
|
||||
this.size = file.size;
|
||||
this.type = file.type;
|
||||
this.deleteType = 'DELETE';
|
||||
},
|
||||
UploadHandler = function (req, res, callback) {
|
||||
this.req = req;
|
||||
this.res = res;
|
||||
this.callback = callback;
|
||||
},
|
||||
serve = function (req, res) {
|
||||
res.setHeader(
|
||||
'Access-Control-Allow-Origin',
|
||||
options.accessControl.allowOrigin
|
||||
);
|
||||
res.setHeader(
|
||||
'Access-Control-Allow-Methods',
|
||||
options.accessControl.allowMethods
|
||||
);
|
||||
res.setHeader(
|
||||
'Access-Control-Allow-Headers',
|
||||
options.accessControl.allowHeaders
|
||||
);
|
||||
var handleResult = function (result, redirect) {
|
||||
if (redirect) {
|
||||
res.writeHead(302, {
|
||||
'Location': redirect.replace(
|
||||
/%s/,
|
||||
encodeURIComponent(JSON.stringify(result))
|
||||
)
|
||||
});
|
||||
res.end();
|
||||
} else {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': req.headers.accept
|
||||
.indexOf('application/json') !== -1 ?
|
||||
'application/json' : 'text/plain'
|
||||
});
|
||||
res.end(JSON.stringify(result));
|
||||
}
|
||||
},
|
||||
setNoCacheHeaders = function () {
|
||||
res.setHeader('Pragma', 'no-cache');
|
||||
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
|
||||
res.setHeader('Content-Disposition', 'inline; filename="files.json"');
|
||||
},
|
||||
handler = new UploadHandler(req, res, handleResult);
|
||||
switch (req.method) {
|
||||
case 'OPTIONS':
|
||||
res.end();
|
||||
break;
|
||||
case 'HEAD':
|
||||
case 'GET':
|
||||
if (req.url === '/') {
|
||||
setNoCacheHeaders();
|
||||
if (req.method === 'GET') {
|
||||
handler.get();
|
||||
} else {
|
||||
res.end();
|
||||
}
|
||||
} else {
|
||||
fileServer.serve(req, res);
|
||||
}
|
||||
break;
|
||||
case 'POST':
|
||||
setNoCacheHeaders();
|
||||
handler.post();
|
||||
break;
|
||||
case 'DELETE':
|
||||
handler.destroy();
|
||||
break;
|
||||
default:
|
||||
res.statusCode = 405;
|
||||
res.end();
|
||||
}
|
||||
};
|
||||
fileServer.respond = function (pathname, status, _headers, files, stat, req, res, finish) {
|
||||
// Prevent browsers from MIME-sniffing the content-type:
|
||||
_headers['X-Content-Type-Options'] = 'nosniff';
|
||||
if (!options.inlineFileTypes.test(files[0])) {
|
||||
// Force a download dialog for unsafe file extensions:
|
||||
_headers['Content-Type'] = 'application/octet-stream';
|
||||
_headers['Content-Disposition'] = 'attachment; filename="' +
|
||||
utf8encode(path.basename(files[0])) + '"';
|
||||
}
|
||||
nodeStatic.Server.prototype.respond
|
||||
.call(this, pathname, status, _headers, files, stat, req, res, finish);
|
||||
};
|
||||
FileInfo.prototype.validate = function () {
|
||||
if (options.minFileSize && options.minFileSize > this.size) {
|
||||
this.error = 'File is too small';
|
||||
} else if (options.maxFileSize && options.maxFileSize < this.size) {
|
||||
this.error = 'File is too big';
|
||||
} else if (!options.acceptFileTypes.test(this.name)) {
|
||||
this.error = 'Filetype not allowed';
|
||||
}
|
||||
return !this.error;
|
||||
};
|
||||
FileInfo.prototype.safeName = function () {
|
||||
// Prevent directory traversal and creating hidden system files:
|
||||
this.name = path.basename(this.name).replace(/^\.+/, '');
|
||||
// Prevent overwriting existing files:
|
||||
while (_existsSync(options.uploadDir + '/' + this.name)) {
|
||||
this.name = this.name.replace(nameCountRegexp, nameCountFunc);
|
||||
}
|
||||
};
|
||||
FileInfo.prototype.initUrls = function (req) {
|
||||
if (!this.error) {
|
||||
var that = this,
|
||||
baseUrl = (options.ssl ? 'https:' : 'http:') +
|
||||
'//' + req.headers.host + options.uploadUrl;
|
||||
this.url = this.deleteUrl = baseUrl + encodeURIComponent(this.name);
|
||||
Object.keys(options.imageVersions).forEach(function (version) {
|
||||
if (_existsSync(
|
||||
options.uploadDir + '/' + version + '/' + that.name
|
||||
)) {
|
||||
that[version + 'Url'] = baseUrl + version + '/' +
|
||||
encodeURIComponent(that.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
UploadHandler.prototype.get = function () {
|
||||
var handler = this,
|
||||
files = [];
|
||||
fs.readdir(options.uploadDir, function (err, list) {
|
||||
list.forEach(function (name) {
|
||||
var stats = fs.statSync(options.uploadDir + '/' + name),
|
||||
fileInfo;
|
||||
if (stats.isFile() && name[0] !== '.') {
|
||||
fileInfo = new FileInfo({
|
||||
name: name,
|
||||
size: stats.size
|
||||
});
|
||||
fileInfo.initUrls(handler.req);
|
||||
files.push(fileInfo);
|
||||
}
|
||||
});
|
||||
handler.callback({files: files});
|
||||
});
|
||||
};
|
||||
UploadHandler.prototype.post = function () {
|
||||
var handler = this,
|
||||
form = new formidable.IncomingForm(),
|
||||
tmpFiles = [],
|
||||
files = [],
|
||||
map = {},
|
||||
counter = 1,
|
||||
redirect,
|
||||
finish = function () {
|
||||
counter -= 1;
|
||||
if (!counter) {
|
||||
files.forEach(function (fileInfo) {
|
||||
fileInfo.initUrls(handler.req);
|
||||
});
|
||||
handler.callback({files: files}, redirect);
|
||||
}
|
||||
};
|
||||
form.uploadDir = options.tmpDir;
|
||||
form.on('fileBegin', function (name, file) {
|
||||
tmpFiles.push(file.path);
|
||||
var fileInfo = new FileInfo(file, handler.req, true);
|
||||
fileInfo.safeName();
|
||||
map[path.basename(file.path)] = fileInfo;
|
||||
files.push(fileInfo);
|
||||
}).on('field', function (name, value) {
|
||||
if (name === 'redirect') {
|
||||
redirect = value;
|
||||
}
|
||||
}).on('file', function (name, file) {
|
||||
var fileInfo = map[path.basename(file.path)];
|
||||
fileInfo.size = file.size;
|
||||
if (!fileInfo.validate()) {
|
||||
fs.unlink(file.path);
|
||||
return;
|
||||
}
|
||||
fs.renameSync(file.path, options.uploadDir + '/' + fileInfo.name);
|
||||
if (options.imageTypes.test(fileInfo.name)) {
|
||||
Object.keys(options.imageVersions).forEach(function (version) {
|
||||
counter += 1;
|
||||
var opts = options.imageVersions[version];
|
||||
imageMagick.resize({
|
||||
width: opts.width,
|
||||
height: opts.height,
|
||||
srcPath: options.uploadDir + '/' + fileInfo.name,
|
||||
dstPath: options.uploadDir + '/' + version + '/' +
|
||||
fileInfo.name
|
||||
}, finish);
|
||||
});
|
||||
}
|
||||
}).on('aborted', function () {
|
||||
tmpFiles.forEach(function (file) {
|
||||
fs.unlink(file);
|
||||
});
|
||||
}).on('error', function (e) {
|
||||
console.log(e);
|
||||
}).on('progress', function (bytesReceived) {
|
||||
if (bytesReceived > options.maxPostSize) {
|
||||
handler.req.connection.destroy();
|
||||
}
|
||||
}).on('end', finish).parse(handler.req);
|
||||
};
|
||||
UploadHandler.prototype.destroy = function () {
|
||||
var handler = this,
|
||||
fileName;
|
||||
if (handler.req.url.slice(0, options.uploadUrl.length) === options.uploadUrl) {
|
||||
fileName = path.basename(decodeURIComponent(handler.req.url));
|
||||
if (fileName[0] !== '.') {
|
||||
fs.unlink(options.uploadDir + '/' + fileName, function (ex) {
|
||||
Object.keys(options.imageVersions).forEach(function (version) {
|
||||
fs.unlink(options.uploadDir + '/' + version + '/' + fileName);
|
||||
});
|
||||
handler.callback({success: !ex});
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
handler.callback({success: false});
|
||||
};
|
||||
if (options.ssl) {
|
||||
require('https').createServer(options.ssl, serve).listen(port);
|
||||
} else {
|
||||
require('http').createServer(serve).listen(port);
|
||||
}
|
||||
}(8888));
|
0
frontend/static/assets/global/plugins/jquery-file-upload/server/node/tmp/.gitignore
vendored
Normal file
0
frontend/static/assets/global/plugins/jquery-file-upload/server/node/tmp/.gitignore
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
# The following directives force the content-type application/octet-stream
|
||||
# and force browsers to display a download dialog for non-image files.
|
||||
# This prevents the execution of script files in the context of the website:
|
||||
ForceType application/octet-stream
|
||||
Header set Content-Disposition attachment
|
||||
<FilesMatch "(?i)\.(gif|jpe?g|png)$">
|
||||
ForceType none
|
||||
Header unset Content-Disposition
|
||||
</FilesMatch>
|
||||
|
||||
# The following directive prevents browsers from MIME-sniffing the content-type.
|
||||
# This is an important complement to the ForceType directive above:
|
||||
Header set X-Content-Type-Options nosniff
|
||||
|
||||
# Uncomment the following lines to prevent unauthorized download of files:
|
||||
#AuthName "Authorization required"
|
||||
#AuthType Basic
|
||||
#require valid-user
|
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/*
|
||||
* jQuery File Upload Plugin PHP Example 5.14
|
||||
* https://github.com/blueimp/jQuery-File-Upload
|
||||
*
|
||||
* Copyright 2010, Sebastian Tschan
|
||||
* https://blueimp.net
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
require('UploadHandler.php');
|
||||
$upload_handler = new UploadHandler();
|
Reference in New Issue
Block a user