client-precache.hbs
3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<style type="text/css">
.panel-body-container {
position: relative;
min-height: 100px;
}
.edit-area {
width: 100%;
position: absolute;
left: 0;
top: 0;
bottom: 0;
}
.edit-area > textarea {
width: 100%;
height: 100%;
}
.pannel-option > * {
margin-left: 10px;
}
.pannel-option .save,
.pannel-option .cancle {
display: none;
}
.pannel-option.pannel-edit .edit {
display: none;
}
.pannel-option.pannel-edit .cancle,
.pannel-option.pannel-edit .save {
display: inline;
}
.edit-area {
display: none;
}
</style>
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href="/"><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="/servers">Projects</a></li>
</ul>
<h4>客户端预加载清单</h4>
</div>
</div>
<!-- media -->
</div>
<div class="contentpanel task-panel" style="padding-bottom:0;">
<!-- pageheader -->
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-right pannel-option">
<a href="javascript:;" class="tooltips edit">编辑</a>
<a href="javascript:;" class="tooltips save">保存</a>
<a href="javascript:;" class="tooltips cancle">取消</a>
</div>
<h4 class="panel-title">预加载清单</h4>
</div>
<div class="panel-body">
<div class="panel-body-container">
<div id="edit-area" class="edit-area">
<textarea id="textarea" class="form-control" pleaceholder="支持多条换行输入"></textarea>
</div>
<div id="static-list" class="static-list"></div>
</div>
</div>
</div>
</div>
<script>
var files = [];
var revision = ''
function resetManifest(list) {
files = list || [];
var h = '';
for (var i = 0; i < files.length; i++) {
h += '<p>' + files[i] + '</p>';
}
$('#static-list').html(h);
}
function getManifest(file) {
$.get(file + '?t=' + new Date().getTime(), function(res) {
if (res && res.files) {
resetManifest(res.files);
revision = res.revision;
};
});
}
function clearCache(url) {
var cloud = ['qiniu', 'qcloud', 'aliyun'];
cloud.forEach(function(val) {
$.post('/cdn_cache/clear', {
query_uri: url,
object_type: 'File',
cloud: val
});
});
}
$('.pannel-option').on('click', '.tooltips', function() {
var $this = $(this),
$par = $this.parent(),
$edit = $('#edit-area');
$par.toggleClass('pannel-edit');
if ($this.hasClass('save')) {
var _files = $('#textarea').val().split('\n');
$.post('/precache/client/save', {
files: _files,
lastRevision: revision
}, function(res) {
if (res.code === 200) {
getManifest(res.data.url);
clearCache(res.data.url);
$edit.hide();
} else {
$par.addClass('pannel-edit');
alert(res.message || '保存失败');
}
});
} else if ($this.hasClass('edit')) {
$('#textarea').val(files.join('\n'));
$edit.show();
} else {
$edit.hide();
}
});
getManifest('//cdn.yoho.cn/{{manifestPath}}');
</script>