зеркало из https://github.com/mozilla/betachannel.git
Adding tiny url support
This commit is contained in:
Родитель
d83e1162bd
Коммит
620f4b773a
|
@ -0,0 +1,24 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
var request = require('request');
|
||||
|
||||
var cache = {};
|
||||
module.exports = function(url, cb) {
|
||||
if (cache[url]) {
|
||||
cb(null, cache[url]);
|
||||
} else {
|
||||
request('http://tinyurl.com/api-create.php?url=' + encodeURI(url), function(err, res, data) {
|
||||
if (err) return cb(err);
|
||||
if (200 !== res.statusCode) {
|
||||
console.log('tinyurl status=', res.statusCode, 'body=', data);
|
||||
return cb(new Error('Tiny Url Error: ' + res.statusCode));
|
||||
} else {
|
||||
cache[url] = data;
|
||||
cb(null, data);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
var reqContext = require('../lib/request_context');
|
||||
var requireDriver = require('../lib/db').requireDriver;
|
||||
var tinyUrl = require('../lib/tiny_url');
|
||||
|
||||
var App = requireDriver('../models', 'app');
|
||||
var Version = requireDriver('../models', 'version');
|
||||
|
@ -54,7 +55,11 @@ module.exports = function(config) {
|
|||
ctx.versions = versions;
|
||||
}
|
||||
ctx.publicUrl = config.publicUrl;
|
||||
res.render('app_install.html', ctx);
|
||||
tinyUrl(config.publicUrl + '/app/v/' + aVersion.versionId + '/install/' + anApp.code, function(err, tUrl) {
|
||||
if (!err) ctx.tinyUrl = tUrl;
|
||||
res.render('app_install.html', ctx);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -6,14 +6,21 @@
|
|||
<p>Try this on your FirefoxOS device.</p>
|
||||
</div>
|
||||
<img src="{{version.icon_url}}" />
|
||||
<div class="app-name">{{version.manifest.name}}</div>
|
||||
<div class="app-name">{{version.manifest.name}} <span class="version">version:{{version.version}}</span></div>
|
||||
<p class="app-name">{{version.manifest.description}}</p>
|
||||
<div class="app-version">{{version.manifest.name}}</div>
|
||||
|
||||
<button data-package-manifest-url="{{version.manifest_url}}" disabled class="install">Install</button>
|
||||
|
||||
<a class="package-link" href="{{signedPackage}}">{{signedPackageSize}}</a>
|
||||
|
||||
<h3>Versions</h3>
|
||||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
<h3>Share this Page</h3>
|
||||
<div class="qrcode" data-qrcode-url="{{ publicUrl }}/app/v/{{version.versionId | string | urlencode}}/install/{{ app.code | urlencode }}"></div>
|
||||
<a href="{{tinyUrl | urlencode }}">{{tinyUrl}}</a>
|
||||
|
||||
<h3>Other Versions</h3>
|
||||
<ol class="versions">
|
||||
{% for ver in versions %}
|
||||
<li><a href="/app/v/{{ ver[0] | string | urlencode }}/install/{{ app.code | urlencode }}">Version {{ ver[1] }}</a>
|
||||
|
@ -21,7 +28,3 @@
|
|||
{% endfor %}
|
||||
</ol>
|
||||
{% endblock %}
|
||||
{% block sidebar %}
|
||||
<a href="">Version {{ ver[1] }}</a>
|
||||
<div class="qrcode" data-qrcode-url="{{ publicUrl }}/app/v/{{version.versionId | string | urlencode}}/install/{{ app.code | urlencode }}"></div>
|
||||
{% endblock %}
|
||||
|
|
Загрузка…
Ссылка в новой задаче