TinyImg 2.0.0:更名、下线 SM.MS、新增后台 Token 设置页

基于 ImgURL 1.x 的二次开发版本,主要变更:

1. 更名
   - 项目定名为 TinyImg,源码中不再出现旧品牌字样(0 处)
   - static/imgurl.js -> static/tinyimg.js
   - db/imgurl-simple.db3 -> db/tinyimg-simple.db3

2. 移除 SM.MS 上传
   - 删除 embed.js 中的 upload.render / smshow / deletesm
   - miniup.html 去掉 SM.MS 选项卡;前台与后台导航移除入口
   - sm.php、functions/sm.php、admin/smadmin.php 改为下线说明页
   - admin/delete.php 移除 type=sm 分支;class.admin.php 删除 querysm()/deletesm()

3. 新增后台 Token 设置(admin/setting.php + functions/token.php)
   - 生成 / 自定义 / 启用 / 停用 / 清空,全部校验 Session CSRF
   - 存储于 db/tinyimg-token.php(首行 <?php exit; 守卫)
   - config.php 的 api_token 仅作兼容回退,保存一次后由文件接管
   - 完整 Token 不写入页面 HTML:默认只渲染掩码,点「显示/复制」时
     经 POST action=reveal(同源 + CSRF + 仅登录会话)按需取回

4. 上传端点鉴权
   - 统一使用 X-TinyImg-Token 请求头,hash_equals 比较,空配置 fail closed
   - 新增 ?ping=1 自检,返回版本、鉴权方式、管理员目录,供写作插件测试连接

5. 版本号
   - 统一为 v2.0.0(20261104),前后台页脚引用 functions/version.php

6. 兼容性修复
   - class.upload.php 中 $size{...} 花括号下标改为 $size[...](PHP 8 已移除该语法)

7. 仓库整理
   - .gitignore 排除 config.php / db/tinyimg-token.php / 运行时目录,
     保留 db/.htaccess 与空模板 db/tinyimg-simple.db3
   - .gitattributes 统一 LF
This commit is contained in:
terry
2026-11-05 17:30:05 +08:00
parent 39e84a0fac
commit aac91aa9b6
180 changed files with 15976 additions and 2 deletions
+112
View File
@@ -0,0 +1,112 @@
'use strict';
(function(root, factory){
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.ctrlVUtil = factory();
}
}(this, function(){
function ctrlVUtil(option){
this.targetElement = null;
this.uploadInput = null;
this.uploadUrl = "http://www.oa.com/screenshot/create-file";
this.isCompleteImg = false;
var that = this;
that.mixinConfig(option);
that.targetElement.addEventListener("mouseover", function() {
that.uploadInput.focus();
});
that.targetElement.addEventListener("click", function() {
that.uploadInput.focus();
});
that.targetElement.addEventListener("mouseleave", function() {
that.uploadInput.blur();
});
that.uploadInput.addEventListener('paste', function(e) {
that.handlePaste(e);
});
}
ctrlVUtil.prototype.mixinConfig = function(option){
this.targetElement = option.targetElement || document.querySelector(".js-upload");
this.uploadInput = this.createInputTarget();
this.isCompleteImg = "isCompleteImg" in option ? option.isCompleteImg : this.isCompleteImg;
this.uploadUrl = option.uploadUrl || this.uploadUrl;
this.data = option.data;
this.success = option.success || function(data) {
console.log(data);
};
this.error = option.error || function(error) {
console.log(error);
};
};
ctrlVUtil.prototype.createInputTarget = function() {
var imgContinaer = document.createElement("div");
imgContinaer.style.cssText = "border:none;margin:0;padding:0;font-size: 0;height:1px;width:1px;opacity:0;position:fixed;z-index:-1;";
imgContinaer.contentEditable = true;
imgContinaer.class = "ui-ctrlv-uploadInput";
this.targetElement.parentNode.insertBefore(imgContinaer, this.targetElement);
return imgContinaer;
};
ctrlVUtil.prototype.handlePaste = function(e){
var that = this;
if (e && e.clipboardData && e.clipboardData.items) {
var item = e.clipboardData.items[0],
that = this;
if (item.type.indexOf('image') != -1) {
var blob = item.getAsFile();
var fileReader = new FileReader();
fileReader.readAsDataURL(blob);
fileReader.addEventListener('load', function(e) {
var file = e.target.result;
that.send(file);
}, false);
} else {
layer.msg('请粘贴image类型!');
}
} else {
setTimeout(function() {
var $img = that.uploadInput.querySelector("img");
if ($img) {
that.send($img.src);
} else {
layer.msg('当前浏览器不支持剪贴板操作!');
return;
}
}, 200);
}
};
ctrlVUtil.prototype.send = function(imgcontent) {
layer.load();
var that = this;
that.uploadInput.innerHTML = "";
var data = that.data || {};
data.content = this.isCompleteImg ? imgcontent : imgcontent.split(';')[1].split(',')[1];
var xhr = new XMLHttpRequest();
xhr.open("post",that.uploadUrl,true);
xhr.onreadystatechange = function(e) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var ret = JSON.parse(xhr.responseText);
that.success && that.success(ret);
} else {
that.error && that.error(e, xhr);
}
}
};
xhr.onerror = function(e) {
that.error && that.error(e, xhr);
};
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var dataString = [];
for(var key in data){
dataString.push(key+"="+encodeURIComponent(data[key]));
}
xhr.send(dataString.join("&"));
};
ctrlVUtil.prototype.alertMsg = function(content){
alert(content);
}
return ctrlVUtil;
}));