/* import sqlite3, { Database } from 'sqlite3'; import os from 'os'; import path from 'path'; import fs from 'fs'; export default class SencondPassCache { private static sql_create_table = 'create table record (' + 'plain_sha varchar PRIMARY KEY NOT NULL unique,' + 'bucket_name varchar,' + 'media_id varchar,' + 'region varchar,' + 'server_type unsigned tinyint,' + 'file_size unsigned mediumint, ' + 'file_name varchar,' + 'media_type varchar,' + 'category_id mediumint,' + 'media_info varchar,' + 'media_cipher_info varchar,' + 'creation_time datetime,' + 'duration_time mediumint )'; private static sql_insert_status = 'insert into record ' + '(plain_sha, media_id, bucket_name, region, server_type, file_size, file_name, media_type, category_id, media_info, media_cipher_info, creation_time, duration_time)' + 'values (?,?,?,?,?,?,?,?,?,?,?,?,?)'; private static sql_delete_status = 'delete from record where plain_sha = ? '; private static sql_query_status = 'select plain_sha, media_id, bucket_name, region, server_type, file_size, file_name, media_type, category_id, media_info, media_cipher_info, creation_time, duration_time from record where plain_sha = ?'; private _db: Database; static async build() { let dbDir = path.join(os.tmpdir(), 'wl_cache/'); let dbfile = path.join(dbDir, 'index.db'); console.log("The database file:" + dbfile + " will be created."); //确保目录存在 if (!fs.existsSync(dbDir)) { fs.mkdirSync(dbDir); } let db = await SencondPassCache.initdb(dbfile); let obj = new SencondPassCache(db); return obj; } private constructor(db: sqlite3.Database) { this._db = db; } insert(bucket: SencondPassBucket) { return new Promise((resolve, reject) => { let sql = SencondPassCache.sql_insert_status; let values: any[] = [ bucket.plain_sha, bucket.media_id, bucket.bucket_name, bucket.region, bucket.server_type, bucket.file_size, bucket.file_name, bucket.media_type, bucket.category_id, bucket.media_info, bucket.media_cipher_info, bucket.creation_time, bucket.duration_time ]; this._db.run(sql, values, e => { if (e !== null) reject(e); else resolve(this); }); }); } delete(sha: string) { return new Promise((resolve, reject) => { let sql = SencondPassCache.sql_delete_status; this._db.get(sql, sha, e => { if (e !== null) reject(e); else { resolve(this); }; }) }); } query(sha: string) { return new Promise((resolve, reject) => { let sql = SencondPassCache.sql_query_status; this._db.get(sql, sha, (e, row) => { if (e !== null) reject(e); else { resolve(row); } }) }); } private static initdb(dbfile: string) { return new Promise((resolve, reject) => { let db = new sqlite3.Database(dbfile, err => { if (err !== null) { console.error(dbfile + ' open failure!'); reject(err); } let sql = SencondPassCache.sql_create_table; db.run(sql, e => { if (e !== null) { if ((e as any).errno === 1) { console.debug(e.message); resolve(db); } else { reject(e); } } else { resolve(db); } }) }) }); } } */ /**缓存数据流结构 */ export interface SencondPassBucket { /** 原文件的摘要 */ plain_sha: string; /** [1-腾讯,2-阿里云,3-亚马逊] */ server_type: number; /** 媒体文件类型[video,audio,image,other] */ media_type: string; /** 唯一id,guid */ media_id: string; /** 存储桶 */ bucket_name: string; /** 区域 */ region: string; /** 文件大小 */ file_size: number; /** 文件名 */ file_name: string; /** 媒体分类id */ category_id: number; /** 自定义内容 */ media_info: string; /** 媒体加密事件 */ media_cipher_info: string; /** url信息 */ media_url: string; /** 创建时间 */ creation_time: string; /** 时长 */ duration_time: number; } // //export interface StreamExistingResult { // /** 0-未找到上传的文件,1-找到上传的文件 */ // Status: number; // /** 唯一id,guid */ // MediaID: string; // /** 存储桶 */ // BucketName: string; // /** 区域 */ // Region: string; // /** [1-腾讯,2-阿里云,3-亚马逊] */ // ServerType: number; // /** 文件大小 */ // FileSize: number; // /** 文件名 */ // FileName: string; // /** 媒体文件类型[video,audio,image,other] */ // MediaType: string; // /** 媒体分类id */ // CategoryID: number; // /** 记录最后修改时间 */ // ModifyTime: string; // /** 自定义内容 */ // MediaInfo?: _IMediaInfo; //} // //export interface _IMediaInfo { // /** 封面图片地址 */ // Cover?: string; // /** 文件扩展名 */ // FileExt?: string; // /** 图片组 */ // ImageGroup?: _IImageGroup[]; //} // ///** // * 图片组 // * @remark 图片的object key: `${FileName}${MediaID}_${Resolution.width}x${Resolution.height}.jpg` // */ //export interface _IImageGroup { // /** 名称 */ // Name: string; // /** 分辨率 */ // Resolution: { width: number, height: number }; //}