借助gitee仓库构建私有图床

借助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";
    }
}

演示

相关推荐
m0_526119403 天前
ssh key生成,gitee配置ssh
运维·gitee·ssh
我最爱吃鱼香茄子3 天前
【保姆级】Git配置用户名和邮箱(全局/局部)解决提交记录不识别、贡献图不亮问题
git·gitee·github·小白教程·git配置·程序员开发工具
++==4 天前
git的安装以及基本命令使用、远程仓库的操作、vscode连接远程仓库进行项目的上传、gitee的使用
linux·git·gitee
QiLinkOS6 天前
QiLink开源生态的三维重构:基于时间、空间与社会价值的底层规则创新白皮书
大数据·c++·人工智能·科技·算法·gitee·开源
IT WorryFree6 天前
GitHub / Gitee / Gitea / GitLab 四平台完整对比(定位、优缺点、适用场景)
gitee·github·gitea
效能革命笔记8 天前
Gitee Team 如何支撑关键领域行业 DevSecOps 落地?
gitee
故渊at10 天前
第二板块:Android 四大组件标准化学理 | 第八篇:Service 后台执行实体与优先级
android·gitee·service·前台服务·后台服务
故渊at10 天前
第二板块:Android 四大组件标准化学理 | 第九篇:BroadcastReceiver 事件分发与有序广播
android·gitee·broadcast·广播·动态注册·静态注册
毛豆的毛豆Y10 天前
新上架!给 Gitee 用户做了个工具:CopoGit
gitee
hashiqimiya10 天前
每日android布局xml文件
android·xml·gitee