able to remove stickerpacks

This commit is contained in:
Tdxdxoz 2020-08-01 21:50:14 +08:00 committed by Travis Ralston
parent 852bfe0667
commit a3b17d1a9f
5 changed files with 46 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { Context, GET, Path, PathParam, POST, Security, ServiceContext } from "typescript-rest";
import { Context, GET, Path, PathParam, POST, DELETE, Security, ServiceContext } from "typescript-rest";
import StickerPack from "../../db/models/StickerPack";
import { ApiError } from "../ApiError";
import { DimensionStickerService, MemoryStickerPack } from "../dimension/DimensionStickerService";
@ -49,6 +49,19 @@ export class AdminStickerService {
return {}; // 200 OK
}
@DELETE
@Path("packs/:id")
@Security([ROLE_ADMIN])
public async removePack(@PathParam("id") packId: number): Promise<any> {
const pack = await StickerPack.findByPk(packId);
if (!pack) throw new ApiError(404, "Sticker pack not found");
await pack.destroy();
Cache.for(CACHE_STICKERS).clear();
return {}; // 200 OK
}
@POST
@Path("packs/import/telegram")
@Security([ROLE_USER, ROLE_ADMIN])

View File

@ -52,10 +52,13 @@
</span>
<ui-switch [checked]="pack.isEnabled" size="small" [disabled]="isUpdating"
(change)="toggleEnabled(pack)"></ui-switch>
<span *ngIf="!pack.isEnabled && !isUpdating" class="removeButton" title="remove stickerpack" (click)="removePack(pack)">
<i class="fa fa-trash"></i>
</span>
</td>
</tr>
</tbody>
</table>
</div>
</my-ibox>
</div>
</div>

View File

@ -7,6 +7,11 @@ tr td:last-child {
vertical-align: text-bottom;
}
.removeButton {
cursor: pointer;
vertical-align: text-bottom;
}
.telegram-import {
margin-bottom: 15px;
}

View File

@ -68,4 +68,23 @@ export class AdminStickerPacksComponent implements OnInit {
this.toaster.pop("error", "Error importing sticker pack");
});
}
public removePack(pack: FE_StickerPack) {
//console.log(this.packs)
//console.log(pack)
this.isUpdating = true;
this.adminStickers.removePack(pack.id).then(() => {
for (let i = 0; i < this.packs.length; ++i)
if (this.packs[i].id === pack.id) {
this.packs.splice(i, 1);
break;
}
this.isUpdating = false;
this.toaster.pop("success", "Sticker pack removed");
}).catch(err => {
console.error(err);
this.isUpdating = false;
this.toaster.pop("error", "Error removing sticker pack");
});
}
}

View File

@ -20,4 +20,8 @@ export class AdminStickersApiService extends AuthedApi {
public importFromTelegram(packUrl: string): Promise<FE_StickerPack> {
return this.authedPost<FE_StickerPack>("/api/v1/dimension/admin/stickers/packs/import/telegram", {packUrl: packUrl}).toPromise();
}
public removePack(packId: number): Promise<any> {
return this.authedDelete("/api/v1/dimension/admin/stickers/packs/" + packId).toPromise();
}
}