parent
2e07b49209
commit
0158b62f88
@ -0,0 +1,52 @@
|
|||||||
|
package com.ruoyi.file.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ftp配置信息
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-24
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "ftp")
|
||||||
|
@Data
|
||||||
|
public class FtpProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 端口
|
||||||
|
*/
|
||||||
|
private String port;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ftp服务ip
|
||||||
|
*/
|
||||||
|
private String serverIp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ftp文件路径
|
||||||
|
*/
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目地址
|
||||||
|
*/
|
||||||
|
private String domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前缀
|
||||||
|
*/
|
||||||
|
private String prefix;
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.ruoyi.file.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.ruoyi.file.config.FtpProperties;
|
||||||
|
import com.ruoyi.file.utils.FileUploadUtils;
|
||||||
|
import com.ruoyi.file.utils.FtpUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FTP 文件存储
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-24
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Primary
|
||||||
|
public class FtpSysFileServiceImpl implements ISysFileService{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FtpUtils ftpUtils;
|
||||||
|
@Autowired
|
||||||
|
private FtpProperties ftpProperties;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadFile(MultipartFile file) throws Exception {
|
||||||
|
Assert.notNull(file, "file is null");
|
||||||
|
String extension = FileUploadUtils.getExtension(file);
|
||||||
|
String url = "";
|
||||||
|
String fileName = UUID.randomUUID() + "." + extension;
|
||||||
|
boolean uploadResult = ftpUtils.uploadFile(String.valueOf(DateUtil.thisYear()),fileName , file.getInputStream());
|
||||||
|
if (uploadResult) {
|
||||||
|
url = ftpProperties.getDomain() + ftpProperties.getPrefix() +"/"+DateUtil.thisYear()+"/"+ fileName;
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.xjs.handler;
|
||||||
|
|
||||||
|
import us.codecraft.webmagic.Page;
|
||||||
|
import us.codecraft.webmagic.Site;
|
||||||
|
import us.codecraft.webmagic.processor.PageProcessor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 米哈游社区爬取资源
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-01-24
|
||||||
|
*/
|
||||||
|
public class MiHoYoRepoPageProcessor implements PageProcessor {
|
||||||
|
|
||||||
|
|
||||||
|
private Site site = Site.me().setRetryTimes(3).setSleepTime(100);
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(Page page) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Site getSite() {
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue