feat(share): reuse existing share and direct links per file
This commit is contained in:
@@ -1354,6 +1354,31 @@ const ShareDB = {
|
||||
return db.prepare('SELECT * FROM shares WHERE id = ?').get(id);
|
||||
},
|
||||
|
||||
// 按目标路径查找已存在分享(用于复用)
|
||||
findExistingByTarget(userId, options = {}) {
|
||||
const {
|
||||
share_type = 'file',
|
||||
file_path = '',
|
||||
storage_type = 'oss'
|
||||
} = options;
|
||||
|
||||
return db.prepare(`
|
||||
SELECT *
|
||||
FROM shares
|
||||
WHERE user_id = ?
|
||||
AND share_type = ?
|
||||
AND share_path = ?
|
||||
AND COALESCE(storage_type, 'oss') = ?
|
||||
ORDER BY id DESC
|
||||
LIMIT 1
|
||||
`).get(
|
||||
userId,
|
||||
share_type,
|
||||
file_path,
|
||||
storage_type || 'oss'
|
||||
);
|
||||
},
|
||||
|
||||
// 验证分享密码
|
||||
verifyPassword(plainPassword, hashedPassword) {
|
||||
return bcrypt.compareSync(plainPassword, hashedPassword);
|
||||
@@ -1492,6 +1517,28 @@ const DirectLinkDB = {
|
||||
return db.prepare('SELECT * FROM direct_links WHERE id = ?').get(id);
|
||||
},
|
||||
|
||||
// 按目标路径查找已存在直链(用于复用)
|
||||
findExistingByTarget(userId, options = {}) {
|
||||
const {
|
||||
file_path = '',
|
||||
storage_type = 'oss'
|
||||
} = options;
|
||||
|
||||
return db.prepare(`
|
||||
SELECT *
|
||||
FROM direct_links
|
||||
WHERE user_id = ?
|
||||
AND file_path = ?
|
||||
AND COALESCE(storage_type, 'oss') = ?
|
||||
ORDER BY id DESC
|
||||
LIMIT 1
|
||||
`).get(
|
||||
userId,
|
||||
file_path,
|
||||
storage_type || 'oss'
|
||||
);
|
||||
},
|
||||
|
||||
getUserLinks(userId) {
|
||||
return db.prepare(`
|
||||
SELECT *
|
||||
|
||||
Reference in New Issue
Block a user