1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00

Screenshot resizing works in the UI now. Still missing rate limiting.

This commit is contained in:
Simo Kinnunen 2014-05-21 14:07:53 +09:00
parent e56d757cde
commit c0d02c4e3a
8 changed files with 43 additions and 47 deletions

View file

@ -400,6 +400,9 @@ program
.option('-r, --storage-url <url>' .option('-r, --storage-url <url>'
, 'URL to storage client' , 'URL to storage client'
, String) , String)
.option('--storage-plugin-image-url <url>'
, 'URL to image storage plugin'
, String)
.option('-u, --connect-sub <endpoint>' .option('-u, --connect-sub <endpoint>'
, 'sub endpoint' , 'sub endpoint'
, cliutil.list) , cliutil.list)
@ -418,6 +421,9 @@ program
if (!options.storageUrl) { if (!options.storageUrl) {
this.missingArgument('--storage-url') this.missingArgument('--storage-url')
} }
if (!options.storagePluginImageUrl) {
this.missingArgument('--storage-plugin-image-url')
}
if (!options.connectSub) { if (!options.connectSub) {
this.missingArgument('--connect-sub') this.missingArgument('--connect-sub')
} }
@ -431,6 +437,7 @@ program
, ssid: options.ssid , ssid: options.ssid
, authUrl: options.authUrl , authUrl: options.authUrl
, storageUrl: options.storageUrl , storageUrl: options.storageUrl
, storagePluginImageUrl: options.storagePluginImageUrl
, endpoints: { , endpoints: {
sub: options.connectSub sub: options.connectSub
, push: options.connectPush , push: options.connectPush
@ -484,10 +491,6 @@ program
, 'port (or $PORT)' , 'port (or $PORT)'
, Number , Number
, process.env.PORT || 7100) , process.env.PORT || 7100)
.option('--public-ip <ip>'
, 'public ip for global access'
, String
, ip())
.option('--save-dir <dir>' .option('--save-dir <dir>'
, 'where to save files' , 'where to save files'
, String , String
@ -495,7 +498,6 @@ program
.action(function(options) { .action(function(options) {
require('./roles/storage/temp')({ require('./roles/storage/temp')({
port: options.port port: options.port
, publicIp: options.publicIp
, saveDir: options.saveDir , saveDir: options.saveDir
}) })
}) })
@ -586,6 +588,10 @@ program
, 'storage port' , 'storage port'
, Number , Number
, 7102) , 7102)
.option('--storage-plugin-image-port <port>'
, 'storage image plugin port'
, Number
, 7103)
.option('--provider <name>' .option('--provider <name>'
, 'provider name (or os.hostname())' , 'provider name (or os.hostname())'
, String , String
@ -676,6 +682,8 @@ program
, '--auth-url', util.format('http://localhost:%d/', options.authPort) , '--auth-url', util.format('http://localhost:%d/', options.authPort)
, '--storage-url' , '--storage-url'
, util.format('http://localhost:%d/', options.storagePort) , util.format('http://localhost:%d/', options.storagePort)
, '--storage-plugin-image-url'
, util.format('http://localhost:%d/', options.storagePluginImagePort)
, '--connect-sub', options.bindAppPub , '--connect-sub', options.bindAppPub
, '--connect-push', options.bindAppPull , '--connect-push', options.bindAppPull
].concat((function() { ].concat((function() {
@ -691,6 +699,14 @@ program
'storage-temp' 'storage-temp'
, '--port', options.storagePort , '--port', options.storagePort
]) ])
// image processor
, procutil.fork(__filename, [
'storage-plugin-image'
, '--port', options.storagePluginImagePort
, '--storage-url'
, util.format('http://localhost:%d/', options.storagePort)
])
] ]
function shutdown() { function shutdown() {

View file

@ -74,13 +74,13 @@ module.exports = function(options) {
})) }))
// Proxied requests must come before any body parsers // Proxied requests must come before any body parsers
app.post('/api/v1/resources', function(req, res) { app.all('/api/v1/s/image/*', function(req, res) {
proxy.web(req, res, { proxy.web(req, res, {
target: options.storageUrl target: options.storagePluginImageUrl
}) })
}) })
app.get('/api/v1/resources/:id', function(req, res) { app.all('/api/v1/s/*', function(req, res) {
proxy.web(req, res, { proxy.web(req, res, {
target: options.storageUrl target: options.storageUrl
}) })

View file

@ -31,7 +31,7 @@ module.exports = syrup.serial()
))) )))
} }
else { else {
resolve(storage.store(res, { resolve(storage.store('image', res, {
filename: util.format('%s.png', options.serial) filename: util.format('%s.png', options.serial)
, contentType: 'image/png' , contentType: 'image/png'
, knownLength: +res.headers['content-length'] , knownLength: +res.headers['content-length']

View file

@ -11,11 +11,11 @@ module.exports = syrup.serial()
var log = logger.createLogger('device:support:storage') var log = logger.createLogger('device:support:storage')
var plugin = Object.create(null) var plugin = Object.create(null)
plugin.store = function(stream, meta) { plugin.store = function(type, stream, meta) {
var resolver = Promise.defer() var resolver = Promise.defer()
var req = request.post({ var req = request.post({
url: util.format('%sapi/v1/resources', options.storageUrl) url: util.format('%sapi/v1/s/%s', options.storageUrl, type)
} }
, function(err, res, body) { , function(err, res, body) {
if (err) { if (err) {
@ -32,7 +32,7 @@ module.exports = syrup.serial()
else { else {
try { try {
var result = JSON.parse(body) var result = JSON.parse(body)
log.info('Uploaded to %s', result.resources.file.url) log.info('Uploaded to %s', result.resources.file.href)
resolver.resolve(result.resources.file) resolver.resolve(result.resources.file)
} }
catch (err) { catch (err) {

View file

@ -1,9 +1,6 @@
var http = require('http') var http = require('http')
var util = require('util')
var express = require('express') var express = require('express')
var Promise = require('bluebird')
var gm = require('gm')
var logger = require('../../../../util/logger') var logger = require('../../../../util/logger')
@ -21,8 +18,8 @@ module.exports = function(options) {
app.set('case sensitive routing', true) app.set('case sensitive routing', true)
app.set('trust proxy', true) app.set('trust proxy', true)
app.get('/api/v1/resources/:id/*', function(req, res) { app.get('/api/v1/s/image/:id/*', function(req, res) {
get(req.params.id, options) get(req.url, options)
.then(function(stream) { .then(function(stream) {
return transform(stream, { return transform(stream, {
crop: parseCrop(req.query.crop) crop: parseCrop(req.query.crop)

View file

@ -1,11 +1,12 @@
var util = require('util') var util = require('util')
var http = require('http') var http = require('http')
var url = require('url')
var Promise = require('bluebird') var Promise = require('bluebird')
module.exports = function(id, options) { module.exports = function(path, options) {
return new Promise(function(resolve, reject) { 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) { .on('response', function(res) {
if (res.statusCode !== 200) { if (res.statusCode !== 200) {
reject(new Error(util.format('HTTP %d', res.statusCode))) reject(new Error(util.format('HTTP %d', res.statusCode)))

View file

@ -7,11 +7,10 @@ var formidable = require('formidable')
var Promise = require('bluebird') var Promise = require('bluebird')
var logger = require('../../util/logger') var logger = require('../../util/logger')
var requtil = require('../../util/requtil')
var Storage = require('../../util/storage') var Storage = require('../../util/storage')
module.exports = function(options) { module.exports = function(options) {
var log = logger.createLogger('storage-temp') var log = logger.createLogger('storage:temp')
, app = express() , app = express()
, server = http.createServer(app) , server = http.createServer(app)
, storage = new Storage() , storage = new Storage()
@ -24,7 +23,7 @@ module.exports = function(options) {
log.info('Cleaning up inactive resource "%s"', id) 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() var form = new formidable.IncomingForm()
Promise.promisify(form.parse, form)(req) Promise.promisify(form.parse, form)(req)
.spread(function(fields, files) { .spread(function(fields, files) {
@ -45,10 +44,12 @@ module.exports = function(options) {
storedFiles.forEach(function(file) { storedFiles.forEach(function(file) {
mapped[file.field] = { mapped[file.field] = {
date: new Date() date: new Date()
, url: util.format( , type: req.params.type
'http://%s:%s/api/v1/resources/%s%s' , id: file.id
, options.publicIp , name: file.name
, options.port , href: util.format(
'/api/v1/s/%s/%s%s'
, req.params.type
, file.id , file.id
, file.name , file.name
? util.format('/%s', path.basename(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) { .catch(function(err) {
log.error('Error storing resource', err.stack) log.error('Error storing resource', err.stack)
res.status(500) res.status(500)
@ -78,18 +71,7 @@ module.exports = function(options) {
}) })
}) })
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)
res.sendfile(file.path)
}
else {
res.send(404)
}
})
app.get('/api/v1/resources/:id/*', function(req, res) {
var file = storage.retrieve(req.params.id) var file = storage.retrieve(req.params.id)
if (file) { if (file) {
res.set('Content-Type', file.type) res.set('Content-Type', file.type)

View file

@ -26,6 +26,6 @@
li(ng-repeat='shot in screenshots').cursor-select li(ng-repeat='shot in screenshots').cursor-select
h5 {{ shot.body.date | date:'yyyy/MM/dd HH:mm:ss' }} h5 {{ shot.body.date | date:'yyyy/MM/dd HH:mm:ss' }}
a(ng-href='{{ shot.body.url }}', target='_blank') a(ng-href='{{ shot.body.url }}', target='_blank')
img(ng-src='{{ shot.body.url + shotSizeUrlParameter() }}') img(ng-src='{{ shot.body.href + shotSizeUrlParameter() }}')
.clearfix .clearfix