首页>代码>springboot实现超级好用的windows+Linux可视化文件操作项目>/spring-boot-filemanager/src/main/java/org/shaofan/controllers/OfficeController.java
package org.shaofan.controllers;


import org.shaofan.utils.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author shaofan
 */
@Controller
@RequestMapping("/office")
public class OfficeController {


    @Value("${fileServer.domain}")
    String domain;

    @Value("${files.docservice.url.api}")
    String doc_api;

    @RequestMapping
    public String office(ModelMap map, String url, String filename) throws UnknownHostException {
        String userAddress = InetAddress.getLocalHost().getHostAddress();
        map.put("key", GenerateRevisionId(userAddress + "/" + filename));

        map.put("url", domain + url);

        map.put("filename", filename);

        map.put("fileType", FileUtils.getExtension(filename).replace(".", ""));

        map.put("doc_api", doc_api);

        map.put("documentType", FileUtils.GetFileType(filename).toString().toLowerCase());

        return "office";
    }

    private static String GenerateRevisionId(String expectedKey) {
        if (expectedKey.length() > 20)
            expectedKey = Integer.toString(expectedKey.hashCode());

        String key = expectedKey.replace("[^0-9-.a-zA-Z_=]", "_");

        return key.substring(0, Math.min(key.length(), 20));
    }
}
最近下载更多
WBelong  LV8 2023年12月28日
jinandfei  LV12 2023年12月27日
yang1115  LV2 2023年4月27日
139465  LV12 2023年3月29日
加油干阳神  LV9 2022年5月8日
crosa_Don  LV18 2022年4月1日
xiex909  LV27 2022年3月30日
回音哥  LV13 2022年2月15日
423256321  LV4 2021年12月27日
Tiam123  LV3 2021年12月22日
最近浏览更多
260858883  LV5 5月28日
Solowen 4月16日
暂无贡献等级
zzzyyy1  LV2 2024年10月4日
15719908287  LV10 2024年9月11日
TY0165  LV20 2024年6月24日
genyuan2014  LV6 2024年5月7日
fff2003  LV9 2024年4月12日
heweimin  LV13 2024年3月8日
小王wang  LV10 2024年2月29日
氟西汀来救你  LV2 2024年1月9日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友