mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-04-27 23:55:01 +00:00
Feat:适配D1数据库
This commit is contained in:
@@ -124,4 +124,3 @@ INSERT OR REPLACE INTO index_metadata (key, last_updated, total_count, last_oper
|
|||||||
VALUES ('main_index', 0, 0, NULL);
|
VALUES ('main_index', 0, 0, NULL);
|
||||||
|
|
||||||
-- 初始化完成
|
-- 初始化完成
|
||||||
-- 数据库已准备就绪,可以开始迁移数据
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* D1 数据库操作工具类
|
* D1 数据库操作工具类
|
||||||
* 用于替代原有的KV存储操作
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class D1Database {
|
class D1Database {
|
||||||
@@ -319,7 +318,7 @@ D1Database.prototype.extractMetadataFields = function(metadata) {
|
|||||||
D1Database.prototype.put = function(key, value, options) {
|
D1Database.prototype.put = function(key, value, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
if (key.startsWith('manage@sysConfig@') || key.startsWith('manage@')) {
|
if (key.startsWith('manage@sysConfig@')) {
|
||||||
return this.putSetting(key, value);
|
return this.putSetting(key, value);
|
||||||
} else if (key.startsWith('manage@index@operation_')) {
|
} else if (key.startsWith('manage@index@operation_')) {
|
||||||
var operationId = key.replace('manage@index@operation_', '');
|
var operationId = key.replace('manage@index@operation_', '');
|
||||||
@@ -336,7 +335,7 @@ D1Database.prototype.put = function(key, value, options) {
|
|||||||
D1Database.prototype.get = function(key) {
|
D1Database.prototype.get = function(key) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (key.startsWith('manage@sysConfig@') || key.startsWith('manage@')) {
|
if (key.startsWith('manage@sysConfig@')) {
|
||||||
return this.getSetting(key);
|
return this.getSetting(key);
|
||||||
} else if (key.startsWith('manage@index@operation_')) {
|
} else if (key.startsWith('manage@index@operation_')) {
|
||||||
var operationId = key.replace('manage@index@operation_', '');
|
var operationId = key.replace('manage@index@operation_', '');
|
||||||
@@ -356,7 +355,7 @@ D1Database.prototype.get = function(key) {
|
|||||||
D1Database.prototype.getWithMetadata = function(key) {
|
D1Database.prototype.getWithMetadata = function(key) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (key.startsWith('manage@sysConfig@') || key.startsWith('manage@')) {
|
if (key.startsWith('manage@sysConfig@')) {
|
||||||
return this.getSetting(key).then(function(value) {
|
return this.getSetting(key).then(function(value) {
|
||||||
return value ? { value: value, metadata: {} } : null;
|
return value ? { value: value, metadata: {} } : null;
|
||||||
});
|
});
|
||||||
@@ -369,7 +368,7 @@ D1Database.prototype.getWithMetadata = function(key) {
|
|||||||
* 通用的delete方法
|
* 通用的delete方法
|
||||||
*/
|
*/
|
||||||
D1Database.prototype.delete = function(key) {
|
D1Database.prototype.delete = function(key) {
|
||||||
if (key.startsWith('manage@sysConfig@') || key.startsWith('manage@')) {
|
if (key.startsWith('manage@sysConfig@')) {
|
||||||
return this.deleteSetting(key);
|
return this.deleteSetting(key);
|
||||||
} else if (key.startsWith('manage@index@operation_')) {
|
} else if (key.startsWith('manage@index@operation_')) {
|
||||||
var operationId = key.replace('manage@index@operation_', '');
|
var operationId = key.replace('manage@index@operation_', '');
|
||||||
@@ -387,7 +386,7 @@ D1Database.prototype.list = function(options) {
|
|||||||
var prefix = options.prefix || '';
|
var prefix = options.prefix || '';
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (prefix.startsWith('manage@sysConfig@') || prefix.startsWith('manage@')) {
|
if (prefix.startsWith('manage@sysConfig@')) {
|
||||||
return this.listSettings(options);
|
return this.listSettings(options);
|
||||||
} else if (prefix.startsWith('manage@index@operation_')) {
|
} else if (prefix.startsWith('manage@index@operation_')) {
|
||||||
return this.listIndexOperations(options).then(function(operations) {
|
return this.listIndexOperations(options).then(function(operations) {
|
||||||
|
|||||||
Reference in New Issue
Block a user