mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-10-10 21:13:10 +08:00
feat(sharing): allow custom share IDs (#2353)
feat: allow custom share IDs - Change sharing ID column from char(12) to varchar(64) - Add new_id field to UpdateSharingReq for renaming share IDs - Add ID validation (max 64 chars, alphanumeric/CJK/hyphens/underscores) - Add conflict check when updating share ID - Add customize_share_id permission (bit 15) Closes OpenListTeam/OpenList#1806
This commit is contained in:
@@ -64,6 +64,14 @@ func UpdateSharing(s *model.SharingDB) error {
|
||||
return errors.WithStack(db.Save(s).Error)
|
||||
}
|
||||
|
||||
func UpdateSharingId(oldId, newId string) error {
|
||||
// Check if new ID already exists
|
||||
if err := db.Where("id = ?", newId).First(&model.SharingDB{}).Error; err == nil {
|
||||
return errors.New("sharing id already exists")
|
||||
}
|
||||
return errors.WithStack(db.Model(&model.SharingDB{}).Where("id = ?", oldId).Update("id", newId).Error)
|
||||
}
|
||||
|
||||
func DeleteSharingById(id string) error {
|
||||
s := model.SharingDB{ID: id}
|
||||
return errors.WithStack(db.Where(s).Delete(&s).Error)
|
||||
|
||||
Reference in New Issue
Block a user