kun-ling-image
v1.0.61
Published
kun ling image tool
Downloads
72
Maintainers
Readme
坤灵图床-文件助手
功能简介:实现图片的统一管理(水印/压缩/空间管理/上传限流等),支持第三方站点(前端)或服务调用坤灵图床服务,提供上传、查询、删除图片的接口(api)功能.
适用范围:适合所有使用npm工具包的前端js框架,包含但不限于vue.
坤灵图床:点击前往
接口调试工具:点击前往
1、环境依赖(不低于)
node v18.19.1+
npm 10.2.4
2、目录结构描述
kun-ling-image
├─config.json // 配置
├─index.js // 实现函数
├─package.json // 包说明文件
└README.md // help
3、接口功能内容
1)上传图片 info 2)查询图片 upload 3)删除图片 delete
4、部署步骤
4.1 安装npm包
npm install kun-ling-image
4.2 调用需要使用的token参数(由坤灵图床管理员提供)
| token类型 | token参数| | ------------ | ------------ | | 静态(static) | token| | 动态(dynamic) | key,appKey,saltValue,rules|
4.3 具体页面调用(以vue为示例)
1)引入
import { dynamicTokenConfigs,staticTokenConfigs,ImageTool } from "kun-ling-image";
2)调用方法(vue)
methods:{
async execImage(type,uptype){ // type操作类型(info/delete/upload)
let imageUrl = 'http://www.image-bed.com/data/upload/api/first-item/20240508194435_818.webp'; // 非必填,当查询、删除图片(type为info/delete)时必填
let imageFile = '图片二进制文件内容';// 非必填,当上传图片(type为upload)时必填
let imageExtend = '{"user_id":'+userInfo.uid+'}';// 非必填,当上传图片(type为upload)时选填
let configs = new staticTokenConfigs();
if(uptype == 'converse_message'){
configs.tokenType = 'static'; // static/dynamic"
configs.token = '817290f3c83acd883186628ad4e4fecc';// 必填
}else if(uptype == 'avatar'){
configs = new dynamicTokenConfigs();
configs.tokenType = 'dynamic'; // static/dynamic
// configs.time = 1716000517; // 选填(时间戳,单位:秒)
configs.key = 'EXBgmKTb'; // 必填
configs.appKey = 'open-doc';// 必填
configs.saltValue = '1234';// 必填
configs.rules = 'md5';// 必填
}
// configs.siteUrl = 'http://www.image-bed.com'; // 非必填,可为空使用默认
let kunLingImage = new ImageTool(configs,'development');// development/production
if(type=='info'){
await kunLingImage.info(imageUrl).then(data=>{
// 实现获取图片信息后续业务逻辑
});
}
if(type=='delete'){
await kunLingImage.delete(imageUrl).then(data=>{
// 实现获取图片信息后续业务逻辑
});
}
if(type=='upload'){
await kunLingImage.upload(imageFile,imageExtend).then(data=>{
// 实现获取图片信息后续业务逻辑
});
}
}
}