Skip to content

Commit

Permalink
📦 NEW: sync web support webDataRemoteRegistry (cnpm#1697)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Jan 29, 2022
1 parent e5c5179 commit 559d5ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions controllers/web/show_sync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var config = require('../../config');

module.exports = function* showSync() {
var name = this.params.name || this.params[0] || this.query.name;
if (!name) {
Expand All @@ -11,9 +13,11 @@ module.exports = function* showSync() {
name = splits[1];
type = splits[0];
}
var syncTaskUrl = config.enableWebDataRemoteRegistry ? `${config.webDataRemoteRegistry}/${name}/sync` : null;
yield this.render('sync', {
type: type,
name: name,
title: 'Sync ' + type + ' - ' + name,
syncTaskUrl,
});
};
11 changes: 9 additions & 2 deletions view/web/sync.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ <h2>Log</h2>
if (type !== 'package') {
name = type + ':' + name;
}
<% if (syncTaskUrl) { %>
var resourceURL = '<%= syncTaskUrl %>';
<% } else { %>
var resourceURL = '/sync/' + name;
<% } %>
$(function() {
var checkLogId = location.hash.match(/logid=(\d+)/);
var logid = checkLogId ? checkLogId[1] : '';
Expand All @@ -26,6 +30,7 @@ <h2>Log</h2>
url: resourceURL + '?sync_upstream=true',
type: 'PUT',
dataType: 'json',
crossDomain: true,
success: handleSyncSucess,
error: function (err) {
var alert = $('<div class="ant-alert ant-alert-error"></div>');
Expand Down Expand Up @@ -57,6 +62,7 @@ <h2>Log</h2>
$.ajax({
url: resourceURL + '/log/' + id,
type: 'GET',
crossDomain: true,
dataType: 'json',
success: function (data) {
if (!data.ok) {
Expand All @@ -72,12 +78,13 @@ <h2>Log</h2>
}
if (syncDone) {
log += '\nSync ' + name + ' complete!';
var logLink = data.logUrl ? (' <a href="' + data.logUrl + '" target="_blank">' + data.logUrl + '</a>') : '';
if (hasFail) {
log += ' But some packages sync failed, you can refresh to sync again.';
location.hash = '';
$notify.html('<div class="ant-alert ant-alert-error">Sync failed.</div>');
$notify.html('<div class="ant-alert ant-alert-error">Sync failed.' + logLink + '</div>');
} else {
$notify.html('<div class="ant-alert ant-alert-success">Sync success.</div>');
$notify.html('<div class="ant-alert ant-alert-success">Sync success.' + logLink + '</div>');
}
clearInterval(timer);
}
Expand Down

0 comments on commit 559d5ba

Please sign in to comment.