Commit 03db1c3d authored by Liang Ding's avatar Liang Ding

🔥 #12556

parent 23f896ae
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Description: Solo POM. Description: Solo POM.
Version: 3.18.3.45, Jan 30, 2019 Version: 3.18.3.46, Feb 7, 2019
Author: <a href="http://88250.b3log.org">Liang Ding</a> Author: <a href="http://88250.b3log.org">Liang Ding</a>
Author: <a href="http://www.annpeter.cn">Ann Peter</a> Author: <a href="http://www.annpeter.cn">Ann Peter</a>
Author: <a href="http://vanessa.b3log.org">Vanessa</a> Author: <a href="http://vanessa.b3log.org">Vanessa</a>
...@@ -79,7 +79,6 @@ ...@@ -79,7 +79,6 @@
<slf4j.version>1.7.5</slf4j.version> <slf4j.version>1.7.5</slf4j.version>
<jsoup.version>1.9.1</jsoup.version> <jsoup.version>1.9.1</jsoup.version>
<flexmark.version>0.40.0</flexmark.version> <flexmark.version>0.40.0</flexmark.version>
<qiniu.version>7.2.11</qiniu.version>
<jetty.version>9.4.12.v20180830</jetty.version> <jetty.version>9.4.12.v20180830</jetty.version>
<commons-cli.version>1.3.1</commons-cli.version> <commons-cli.version>1.3.1</commons-cli.version>
<commons-codec.version>1.10</commons-codec.version> <commons-codec.version>1.10</commons-codec.version>
...@@ -195,12 +194,6 @@ ...@@ -195,12 +194,6 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>${qiniu.version}</version>
</dependency>
<dependency> <dependency>
<groupId>commons-cli</groupId> <groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
...@@ -257,22 +250,6 @@ ...@@ -257,22 +250,6 @@
<version>${user-agent-utils.version}</version> <version>${user-agent-utils.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>${aliyun-sdk-oss.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
<exclusion>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -35,7 +35,7 @@ import java.util.regex.Pattern; ...@@ -35,7 +35,7 @@ import java.util.regex.Pattern;
* Permalink query service. * Permalink query service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.5, Sep 26, 2018 * @version 1.0.0.6, Feb 7, 2019
* @since 0.6.1 * @since 0.6.1
*/ */
@Service @Service
...@@ -64,10 +64,10 @@ public class PermalinkQueryService { ...@@ -64,10 +64,10 @@ public class PermalinkQueryService {
public static final String[] RESERVED_LINKS = new String[]{ public static final String[] RESERVED_LINKS = new String[]{
"/", "/article", "/tags.html", "/tags", "/page", "/atom.xml", "/rss.xml", "/articles/random", "/captcha", "/kill-browser", "/", "/article", "/tags.html", "/tags", "/page", "/atom.xml", "/rss.xml", "/articles/random", "/captcha", "/kill-browser",
"/article/comments", "/add-article-from-symphony-comment.do", "/page/comments", "/get-article-content", "/sitemap.xml", "/article/comments", "/add-article-from-symphony-comment.do", "/page/comments", "/get-article-content", "/sitemap.xml",
"/login", "/logout", "/forgot", "/get-article-content", "/admin-index.do", "/admin-article.do", "/admin-article-list.do", "/logout", "/get-article-content", "/admin-index.do", "/admin-article.do", "/admin-article-list.do",
"/admin-link-list.do", "/admin-preference.do", "/admin-file-list.do", "/admin-page-list.do", "/admin-others.do", "/admin-link-list.do", "/admin-preference.do", "/admin-file-list.do", "/admin-page-list.do", "/admin-others.do",
"/admin-draft-list.do", "/admin-user-list.do", "/admin-plugin-list.do", "/admin-main.do", "/admin-about.do", "/admin-label", "/admin-draft-list.do", "/admin-user-list.do", "/admin-plugin-list.do", "/admin-main.do", "/admin-about.do", "/admin-label",
"/admin-about.do", "/init", "/register", "/upload" "/admin-about.do", "/start"
}; };
/** /**
......
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.service.oss;
import com.aliyun.oss.OSSClient;
import jodd.io.upload.FileUpload;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.solo.model.Option;
import org.b3log.solo.service.OptionQueryService;
import org.json.JSONObject;
import java.net.URL;
/**
* 阿里云对象存储服务.
*
* @author <a href="https://github.com/hzchendou">hzchendou</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, Dec 23, 2018
* @since 2.9.8
*/
public class AliyunOssService implements OssService {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(AliyunOssService.class);
/**
* 阿里云 Oss 配置报错文案.
*/
public static final String ERR_MSG =
"Aliyun settings failed, please visit http://hzchendou.com/articles/2018/12/09/1544343203696.html for more details";
/**
* Oss 客户端.
*/
private OSSClient ossClient;
/**
* 阿里云数据库对象.
*/
private JSONObject aliyun;
/**
* 文件路径前缀.
*/
private String OSS_FILE_PATH_PREFIX = null;
/**
* 创建阿里云对象存储.
*/
public AliyunOssService() {
try {
final BeanManager beanManager = BeanManager.getInstance();
final OptionQueryService optionQueryService = beanManager.getReference(OptionQueryService.class);
aliyun = optionQueryService.getOptions(Option.CATEGORY_C_ALIYUN);
if (null == aliyun) {
LOGGER.log(Level.ERROR, ERR_MSG);
throw new IllegalStateException();
}
ossClient = new OSSClient(aliyun.optString(Option.ID_C_ALIYUN_DOMAIN),
aliyun.optString(Option.ID_C_ALIYUN_ACCESS_KEY), aliyun.optString(Option.ID_C_ALIYUN_SECRET_KEY));
initFilfPrefix();
} catch (final Exception e) {
LOGGER.log(Level.ERROR, ERR_MSG);
throw new IllegalStateException(ERR_MSG);
}
}
@Override
public String upload(final FileUpload file, final String fileName) throws Exception {
try {
ossClient.putObject(aliyun.optString(Option.ID_C_ALIYUN_BUCKET), fileName, file.getFileInputStream());
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Uploads file to Aliyun OSS failed", e);
throw new Exception(ERR_MSG);
}
return OSS_FILE_PATH_PREFIX + fileName;
}
@Override
public void close() {
ossClient.shutdown();
}
/**
* 初始化路径前缀.
*/
private void initFilfPrefix() {
try {
String bucketName = aliyun.optString(Option.ID_C_ALIYUN_BUCKET);
URL url = new URL(aliyun.optString(Option.ID_C_ALIYUN_DOMAIN));
OSS_FILE_PATH_PREFIX = "http://" + bucketName + "." + url.getHost() + "/";
} catch (final Exception e) {
LOGGER.log(Level.ERROR, ERR_MSG);
throw new IllegalStateException(ERR_MSG);
}
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.service.oss;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.service.annotation.Service;
import org.b3log.solo.model.Option;
import org.b3log.solo.service.OptionQueryService;
import org.json.JSONObject;
import java.util.Objects;
import static org.b3log.solo.model.Option.*;
/**
* Cloud object storage service.
*
* @author <a href="https://github.com/hzchendou">hzchendou</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, Dec 23, 2018
* @since 2.9.8
*/
@Service
public class CloudStorageService {
/**
* Creates an object storage service.
*
* @return an object storage service
*/
public OssService createStorage() {
final BeanManager beanManager = BeanManager.getInstance();
final OptionQueryService optionQueryService = beanManager.getReference(OptionQueryService.class);
String cloudServer = CATEGORY_C_QINIU;
final JSONObject cloudStorageJson = optionQueryService.getOptions(Option.CATEGORY_C_CLOU_STORAGE);
if (cloudStorageJson != null) {
cloudServer = cloudStorageJson.getString(ID_C_CLOUD_STORAGE_KEY);
}
if (cloudServer == null || cloudServer.length() < 1) {
throw new IllegalStateException(AliyunOssService.ERR_MSG);
}
if (Objects.equals(cloudServer, CATEGORY_C_ALIYUN)) {
return new AliyunOssService();
}
if (Objects.equals(cloudServer, CATEGORY_C_QINIU)) {
return new QiniuOssService();
}
throw new IllegalStateException(AliyunOssService.ERR_MSG);
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.service.oss;
import jodd.io.upload.FileUpload;
/**
* 对象存储服务.
*
* @author <a href="https://github.com/hzchendou">hzchendou</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, Dec 23, 2018
* @since 2.9.8
*/
public interface OssService {
/**
* 上传文件,返回文件链接.
*
* @param file the specified file
* @param fileName the specified filename
* @return 文件外链地址
*/
String upload(final FileUpload file, final String fileName) throws Exception;
/**
* 销毁.
*/
default void close() {
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.service.oss;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import jodd.io.upload.FileUpload;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.solo.model.Option;
import org.b3log.solo.service.OptionQueryService;
import org.json.JSONObject;
/**
* 七牛云对象存储服务.
*
* @author <a href="https://github.com/hzchendou">hzchendou</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.1.0, Feb 6, 2019
* @since 2.9.8
*/
public class QiniuOssService implements OssService {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(CloudStorageService.class);
private static final String ERR_MSG = "Qiniu settings failed, please visit https://hacpai.com/article/1442418791213 for more details";
/**
* 七牛数据库对象.
*/
private JSONObject qiniu;
/**
* 上传文件对象.
*/
private UploadManager uploadManager;
/**
* 上传凭证 Token.
*/
private String uploadToken;
/**
* 创建七牛云 Oss 服务对象
*/
public QiniuOssService() {
try {
final BeanManager beanManager = BeanManager.getInstance();
final OptionQueryService optionQueryService = beanManager.getReference(OptionQueryService.class);
qiniu = optionQueryService.getOptions(Option.CATEGORY_C_QINIU);
if (null == qiniu) {
LOGGER.log(Level.ERROR, ERR_MSG);
throw new IllegalStateException();
}
Auth auth = Auth.create(qiniu.optString(Option.ID_C_QINIU_ACCESS_KEY),
qiniu.optString(Option.ID_C_QINIU_SECRET_KEY));
uploadToken = auth.uploadToken(qiniu.optString(Option.ID_C_QINIU_BUCKET), null, 3600 * 6, null);
uploadManager = new UploadManager(new Configuration());
} catch (final Exception e) {
LOGGER.log(Level.ERROR, ERR_MSG);
throw new IllegalStateException(ERR_MSG);
}
}
@Override
public String upload(final FileUpload file, final String fileName) throws Exception {
try {
final String contentType = file.getHeader().getContentType();
uploadManager.put(file.getFileInputStream(), fileName, uploadToken, null, contentType);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Uploads file to Qiniu OSS failed", e);
throw new Exception(ERR_MSG);
}
return qiniu.optString(Option.ID_C_QINIU_DOMAIN) + fileName;
}
}
...@@ -92,11 +92,6 @@ public final class Solos { ...@@ -92,11 +92,6 @@ public final class Solos {
*/ */
public static final String GRAVATAR; public static final String GRAVATAR;
/**
* Local file upload dir path.
*/
public static final String UPLOAD_DIR_PATH;
/** /**
* Mobile skin. * Mobile skin.
*/ */
...@@ -139,12 +134,6 @@ public final class Solos { ...@@ -139,12 +134,6 @@ public final class Solos {
B3LOG_SYMPHONY_SERVE_PATH = solo.getString("symphony.servePath"); B3LOG_SYMPHONY_SERVE_PATH = solo.getString("symphony.servePath");
FAVICON_API = solo.getString("faviconAPI"); FAVICON_API = solo.getString("faviconAPI");
GRAVATAR = solo.getString("gravatar"); GRAVATAR = solo.getString("gravatar");
String dir = solo.getString("uploadDir");
if (StringUtils.isNotBlank(dir) && !StringUtils.endsWith(dir, "/")) {
dir += "/";
}
UPLOAD_DIR_PATH = dir;
String mobileSkin = Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME; String mobileSkin = Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME;
try { try {
mobileSkin = solo.getString("mobile.skin"); mobileSkin = solo.getString("mobile.skin");
......
...@@ -18,12 +18,11 @@ ...@@ -18,12 +18,11 @@
# #
# Description: Solo configurations. # Description: Solo configurations.
# Version: 2.4.0.3, Dec 8, 2018 # Version: 2.4.0.4, Feb 7, 2019
# Author: Liang Ding # Author: Liang Ding
# #
mobile.skin=Jane mobile.skin=Jane
uploadDir=
rhythm.servePath=https://rhythm.b3log.org:443 rhythm.servePath=https://rhythm.b3log.org:443
symphony.servePath=https://hacpai.com:443 symphony.servePath=https://hacpai.com:443
......
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