砍材农夫砍材农夫
  • 微信记账小程序
  • java
  • redis
  • mysql
  • 场景类
  • 框架类
  • vuepress搭建
  • hexo搭建
  • 云图
  • llm wiki

    • 基于karpathy
    • gradle
  • 常用工具

    • git
    • gradle
    • Zadig
    • it-tools
    • 开源推荐
    • curl
  • 大前端

    • nodejs
    • npm
    • webpack
    • 微信
    • 正则
    • uniapp
    • app
  • java

    • java基础
    • jdk体系
    • jvm
    • spring
    • spring_cloud
    • spring_boot
    • 分库分表
    • zookeeper
  • python

    • python基础
    • python高级
    • python框架
  • 算法

    • 算法
  • 网关

    • spring_cloud_gateway
    • openresty
  • 高可用

    • 秒杀
    • 分布式
    • 缓存一致
  • MQ

    • MQ
    • rabbitMQ
    • rocketMQ
    • kafka
  • 其它

    • 设计模式
    • 领域驱动(ddd)
  • 关系型数据库

    • mysql5.0
    • mysql8.0
  • 非关系型数据库

    • redis
    • mongoDB
  • 分布式/其他

    • ShardingSphere
    • 区块链
  • 向量数据库

    • M3E
    • OPEN AI
  • Jmeter
  • fiddler
  • wireshark
  • AI入门
  • AI大模型
  • AI插件
  • AI集成框架
  • 相关算法
  • AI训练师
  • 量化交易
  • gitee
  • github
  • infoq
  • osc
  • 砍材工具
  • 关于
  • 相关运营
  • docker
  • k8s
  • devops
  • nginx
  • 元宇宙
  • 区块链
  • 物联网
  • linux
  • webrtc
  • web3.0
  • gitee
  • github
  • infoq
  • osc
  • 砍材工具
  • 关于
  • 中考
  • 投资
  • 保险
  • 思
  • 微信记账小程序
  • java
  • redis
  • mysql
  • 场景类
  • 框架类
  • vuepress搭建
  • hexo搭建
  • 云图
  • llm wiki

    • 基于karpathy
    • gradle
  • 常用工具

    • git
    • gradle
    • Zadig
    • it-tools
    • 开源推荐
    • curl
  • 大前端

    • nodejs
    • npm
    • webpack
    • 微信
    • 正则
    • uniapp
    • app
  • java

    • java基础
    • jdk体系
    • jvm
    • spring
    • spring_cloud
    • spring_boot
    • 分库分表
    • zookeeper
  • python

    • python基础
    • python高级
    • python框架
  • 算法

    • 算法
  • 网关

    • spring_cloud_gateway
    • openresty
  • 高可用

    • 秒杀
    • 分布式
    • 缓存一致
  • MQ

    • MQ
    • rabbitMQ
    • rocketMQ
    • kafka
  • 其它

    • 设计模式
    • 领域驱动(ddd)
  • 关系型数据库

    • mysql5.0
    • mysql8.0
  • 非关系型数据库

    • redis
    • mongoDB
  • 分布式/其他

    • ShardingSphere
    • 区块链
  • 向量数据库

    • M3E
    • OPEN AI
  • Jmeter
  • fiddler
  • wireshark
  • AI入门
  • AI大模型
  • AI插件
  • AI集成框架
  • 相关算法
  • AI训练师
  • 量化交易
  • gitee
  • github
  • infoq
  • osc
  • 砍材工具
  • 关于
  • 相关运营
  • docker
  • k8s
  • devops
  • nginx
  • 元宇宙
  • 区块链
  • 物联网
  • linux
  • webrtc
  • web3.0
  • gitee
  • github
  • infoq
  • osc
  • 砍材工具
  • 关于
  • 中考
  • 投资
  • 保险
  • 思
  • 架构和准备
  • 具体实现细节
    • 仓库和源码地址
    • 服务端
    • yaml配置
    • 启动类
    • 同步git 云图
  • 演示

借助gitee仓库构建私有图床

架构和准备

  1. 创建gitee服务端仓库
  2. 创建gitee图床仓库
  3. 日常图片存储gitee仓库,通过git提交,保障本地电脑和云上备份双份
  4. 创建spring-boot服务端应用,实现预览图片路径为gitee图床
  5. 创建spring-boot客户端应用,实现远程服务端同步git pull命令
  6. 部署服务通过nginx域名代理
  7. 服务端部署

具体实现细节

仓库和源码地址

gitee 图片仓库[https://gitee.com/kcnf_open/wiki]

gitee 服务端仓库[https://gitee.com/kcnf_open/kcnf-wiki]

服务端

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

yaml配置

#app
server:
  port: 8086
  servlet:
    context-path: /
#spring
spring:
  main:
    allow-bean-definition-overriding: true
  devtools:
    restart:
      enabled: false
  profiles:
    active: dev
  web:
    resources:
      static-locations: file:${IMAGE_BASE_PATH:/data/wiki}/, classpath:/static/

启动类

package com.jysemel.kcnf;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * @author jysemel
 */
@Slf4j
@EnableScheduling
@SpringBootApplication
public class WikiApplication implements CommandLineRunner {

	@Autowired
	private ApplicationContext context;

	public static void main(String[] args) {
		log.info("砍材农夫	开始启动........................................");
		SpringApplication.run(WikiApplication.class, args);
		log.info("砍材农夫	启动成功........................................");
	}


	@Override
	public void run(String... args) throws Exception {
		// 更简单的方法:直接输出配置值
		String path = context.getEnvironment().getProperty("IMAGE_BASE_PATH");
		log.info(">>> IMAGE_BASE_PATH {}", path);
		log.info(">>> static-locations {}" , context.getEnvironment().getProperty("spring.web.resources.static-locations"));
	}

}

同步git 云图

package com.jysemel.kcnf.controller;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Slf4j
@RestController
public class GitController {

    @Autowired
    private ApplicationContext context;


    @SneakyThrows
    @GetMapping("/admin/pull")
    public String pull() throws IOException {
        String path = context.getEnvironment().getProperty("IMAGE_BASE_PATH");
        log.info(">>> IMAGE_BASE_PATH {}", path);
        Process process = Runtime.getRuntime().exec("git -C "+ path +" pull");
        int code = process.waitFor();
        return code == 0 ? "success" : "failed";
    }
}

演示

示例图片

示例图片

最近更新: 2026/5/2 22:03
Contributors: kcnf