Commit e8c69eb5 authored by Liang Ding's avatar Liang Ding

#12372

parent 7a74d407
......@@ -408,7 +408,7 @@ public class AdminConsole {
IOUtils.closeQuietly(inputStream);
response.setContentType("application/zip");
final String fileName = "solo-" + date + ".sql.zip";
final String fileName = "solo-sql-" + date + ".zip";
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
final ServletOutputStream outputStream = response.getOutputStream();
......@@ -462,7 +462,7 @@ public class AdminConsole {
IOUtils.closeQuietly(inputStream);
response.setContentType("application/zip");
final String fileName = "solo-" + date + ".json.zip";
final String fileName = "solo-json-" + date + ".zip";
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
final ServletOutputStream outputStream = response.getOutputStream();
......@@ -498,12 +498,13 @@ public class AdminConsole {
final String tmpDir = System.getProperty("java.io.tmpdir");
final String date = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
String localFilePath = tmpDir + File.separator + "solo-" + date + "-hexo/";
String localFilePath = tmpDir + File.separator + "solo-hexo-" + date;
LOGGER.trace(localFilePath);
final File localFile = new File(localFilePath);
final File postDir = new File(localFilePath + "posts");
final File passwordDir = new File(localFilePath + "passwords");
final File draftDir = new File(localFilePath + "drafts");
final File postDir = new File(localFilePath + File.separator + "posts");
final File passwordDir = new File(localFilePath + File.separator + "passwords");
final File draftDir = new File(localFilePath + File.separator + "drafts");
try {
if (!postDir.mkdirs()) {
......@@ -532,7 +533,7 @@ public class AdminConsole {
IOUtils.closeQuietly(inputStream);
response.setContentType("application/zip");
final String fileName = "solo-" + date + ".hexo.zip";
final String fileName = "solo-hexo-" + date + ".zip";
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
final ServletOutputStream outputStream = response.getOutputStream();
......@@ -575,7 +576,7 @@ public class AdminConsole {
final String text = article.optString("front") + "\n----\n" + article.optString("content");
try {
final OutputStream output = new FileOutputStream(dirPath + filename);
final OutputStream output = new FileOutputStream(dirPath + File.separator + filename);
IOUtils.write(text.getBytes("UTF-8"), output);
IOUtils.closeQuietly(output);
} catch (final Exception e) {
......
......@@ -51,6 +51,7 @@
<button class="margin12" onclick="admin.others.exportSQL();">${exportSQLLabel}</button>
</#if>
<button class="margin12" onclick="admin.others.exportJSON();">${exportJSONLabel}</button>
<button class="margin12" onclick="admin.others.exportHexo();">${exportHexoLabel}</button>
</div>
</div>
${plugins}
......@@ -105,6 +105,27 @@ admin.others = {
}
});
},
/*
* @description 导出数据为 Hexo Markdown 文件
*/
exportHexo: function () {
$("#tipMsg").text("");
$.ajax({
url: latkeConfig.servePath + "/console/export/hexo",
type: "GET",
cache: false,
success: function (result, textStatus) {
// AJAX 下载文件的话这里会发两次请求,用 sc 来判断是否是文件,如果没有 sc 说明文件可以下载(实际上就是 result)
if (!result.sc) {
// 再发一次请求进行正式下载
window.location = latkeConfig.servePath + "/console/export/hexo";
} else {
$("#tipMsg").text(result.msg);
}
}
});
},
/*
* 获取未使用的标签。
* XXX: Not used this function yet.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment