Skip to content

Commit

Permalink
update imageVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
revir committed Oct 10, 2017
1 parent 9c4e65e commit 9edef79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 9 additions & 2 deletions index.js
Expand Up @@ -26,6 +26,7 @@ var settings = {
"bucket": process.env.UPYUN_UPLOADS_BUCKET || undefined,
"path": process.env.UPYUN_UPLOADS_PATH || undefined,
"host": process.env.UPYUN_HOST,
"imageVersion": process.env.UPYUN_IMAGE_VERSION || undefined,
};

function fetchSettings(callback) {
Expand Down Expand Up @@ -74,6 +75,12 @@ function fetchSettings(callback) {
settings.endpoint = newSettings.endpoint;
}

if (!newSettings.imageVersion) {
settings.imageVersion = process.env.UPYUN_IMAGE_VERSION || undefined;
} else {
settings.imageVersion = newSettings.imageVersion;
}

if (settings.path) {
UpyunConn().makeDir(getUpyunDir(), function (err, result) {
if (err) {
Expand Down Expand Up @@ -313,8 +320,8 @@ function uploadToUpyun(filename, err, buffer, callback) {
UpyunConn().putFile(remotePath, buffer)
.then((data) => {
// console.log(data);
const host = getUpyunHost();
const remoteHref = host + remotePath;
var host = getUpyunHost();
var remoteHref = host + remotePath + (settings.imageVersion || '');
callback(null, {
name: filename,
url: remoteHref
Expand Down
9 changes: 8 additions & 1 deletion templates/admin/plugins/upyun-uploads.tpl
Expand Up @@ -12,6 +12,7 @@ export UPYUN_UPLOADS_BUCKET="mybucket"
export UPYUN_UPLOADS_PATH="path"
export UPYUN_ENDPOINT="v0.api.upyun.com"
export UPYUN_HOST="hostname domain"
export UPYUN_IMAGE_VERSION="!format"
</code></pre>

<p>
Expand All @@ -21,7 +22,9 @@ export UPYUN_HOST="hostname domain"
http://cdn.mywebsite.com/uuid.jpg.<br/>
Upyun path can be set to a custom asset path. For example, if set to /assets, then the asset url is
http://mybucket.b0.upaiyun.com/assets/uuid.jpg.<br/>
If both are asset host and path are set, then the url will be http://cdn.mywebsite.com/assets/uuid.jpg.
If both host and path are set, then the url will be http://cdn.mywebsite.com/assets/uuid.jpg.
If image version is set, like '!format'(don't forget the '!'), then the url will be http://cdn.mywebsite.com/assets/uuid.jpg!format.
See <a href="https://docs.upyun.com/cloud/image/">图片处理</a>.
</p>

<div class="alert alert-warning">
Expand Down Expand Up @@ -51,6 +54,10 @@ export UPYUN_HOST="hostname domain"
<option value="v2.api.upyun.com">联通(网通)线路 (v2.api.upyun.com)</option>
<option value="v3.api.upyun.com">移动(铁通)线路 (v3.api.upyun.com)</option>
</select>

<label for="imageVersion">Image Version</label><br/>
<input type="text" id="imageVersion" name="imageVersion" value="{imageVersion}" title="Image Version" class="form-control input-lg"
placeholder="!format"><br/>
<br/>

<button class="btn btn-primary" type="submit">Save</button>
Expand Down

0 comments on commit 9edef79

Please sign in to comment.