mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
Screenshot resizing works in the UI now. Still missing rate limiting.
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
var http = require('http')
|
||||
var util = require('util')
|
||||
|
||||
var express = require('express')
|
||||
var Promise = require('bluebird')
|
||||
var gm = require('gm')
|
||||
|
||||
var logger = require('../../../../util/logger')
|
||||
|
||||
@@ -21,8 +18,8 @@ module.exports = function(options) {
|
||||
app.set('case sensitive routing', true)
|
||||
app.set('trust proxy', true)
|
||||
|
||||
app.get('/api/v1/resources/:id/*', function(req, res) {
|
||||
get(req.params.id, options)
|
||||
app.get('/api/v1/s/image/:id/*', function(req, res) {
|
||||
get(req.url, options)
|
||||
.then(function(stream) {
|
||||
return transform(stream, {
|
||||
crop: parseCrop(req.query.crop)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
var util = require('util')
|
||||
var http = require('http')
|
||||
var url = require('url')
|
||||
|
||||
var Promise = require('bluebird')
|
||||
|
||||
module.exports = function(id, options) {
|
||||
module.exports = function(path, options) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
http.get(util.format('%sapi/v1/resources/%s', options.storageUrl, id))
|
||||
http.get(url.resolve(options.storageUrl, path))
|
||||
.on('response', function(res) {
|
||||
if (res.statusCode !== 200) {
|
||||
reject(new Error(util.format('HTTP %d', res.statusCode)))
|
||||
|
||||
@@ -7,11 +7,10 @@ var formidable = require('formidable')
|
||||
var Promise = require('bluebird')
|
||||
|
||||
var logger = require('../../util/logger')
|
||||
var requtil = require('../../util/requtil')
|
||||
var Storage = require('../../util/storage')
|
||||
|
||||
module.exports = function(options) {
|
||||
var log = logger.createLogger('storage-temp')
|
||||
var log = logger.createLogger('storage:temp')
|
||||
, app = express()
|
||||
, server = http.createServer(app)
|
||||
, storage = new Storage()
|
||||
@@ -24,7 +23,7 @@ module.exports = function(options) {
|
||||
log.info('Cleaning up inactive resource "%s"', id)
|
||||
})
|
||||
|
||||
app.post('/api/v1/resources', function(req, res) {
|
||||
app.post('/api/v1/s/:type', function(req, res) {
|
||||
var form = new formidable.IncomingForm()
|
||||
Promise.promisify(form.parse, form)(req)
|
||||
.spread(function(fields, files) {
|
||||
@@ -45,10 +44,12 @@ module.exports = function(options) {
|
||||
storedFiles.forEach(function(file) {
|
||||
mapped[file.field] = {
|
||||
date: new Date()
|
||||
, url: util.format(
|
||||
'http://%s:%s/api/v1/resources/%s%s'
|
||||
, options.publicIp
|
||||
, options.port
|
||||
, type: req.params.type
|
||||
, id: file.id
|
||||
, name: file.name
|
||||
, href: util.format(
|
||||
'/api/v1/s/%s/%s%s'
|
||||
, req.params.type
|
||||
, file.id
|
||||
, file.name
|
||||
? util.format('/%s', path.basename(file.name))
|
||||
@@ -60,14 +61,6 @@ module.exports = function(options) {
|
||||
})()
|
||||
})
|
||||
})
|
||||
.catch(requtil.ValidationError, function(err) {
|
||||
res.status(400)
|
||||
.json({
|
||||
success: false
|
||||
, error: 'ValidationError'
|
||||
, validationErrors: err.errors
|
||||
})
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.error('Error storing resource', err.stack)
|
||||
res.status(500)
|
||||
@@ -78,18 +71,7 @@ module.exports = function(options) {
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/api/v1/resources/:id', function(req, res) {
|
||||
var file = storage.retrieve(req.params.id)
|
||||
if (file) {
|
||||
res.set('Content-Type', file.type)
|
||||
res.sendfile(file.path)
|
||||
}
|
||||
else {
|
||||
res.send(404)
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/api/v1/resources/:id/*', function(req, res) {
|
||||
app.get('/api/v1/s/:type/:id/*', function(req, res) {
|
||||
var file = storage.retrieve(req.params.id)
|
||||
if (file) {
|
||||
res.set('Content-Type', file.type)
|
||||
|
||||
Reference in New Issue
Block a user