1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
6 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
7 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
8 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
9 import org
.asamk
.signal
.manager
.Manager
;
10 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
11 import org
.asamk
.signal
.output
.JsonWriter
;
12 import org
.asamk
.signal
.output
.OutputWriter
;
13 import org
.asamk
.signal
.output
.PlainTextWriter
;
14 import org
.slf4j
.Logger
;
15 import org
.slf4j
.LoggerFactory
;
18 import java
.io
.IOException
;
21 public class UploadStickerPackCommand
implements JsonRpcLocalCommand
{
23 private static final Logger logger
= LoggerFactory
.getLogger(UploadStickerPackCommand
.class);
26 public String
getName() {
27 return "uploadStickerPack";
31 public void attachToSubparser(final Subparser subparser
) {
32 subparser
.help("Upload a new sticker pack, consisting of a manifest file and the stickers images.");
33 subparser
.addArgument("path")
34 .help("The path of the manifest.json or a zip file containing the sticker pack you wish to upload.");
38 public void handleCommand(
41 final OutputWriter outputWriter
42 ) throws CommandException
{
43 var path
= new File(ns
.getString("path"));
46 var url
= m
.uploadStickerPack(path
);
47 switch (outputWriter
) {
48 case PlainTextWriter writer
-> writer
.println("{}", url
.getUrl());
49 case JsonWriter writer
-> {
50 writer
.write(Map
.of("url", url
.getUrl()));
53 } catch (IOException e
) {
54 throw new IOErrorException("Upload error (maybe image size too large):" + e
.getMessage(), e
);
55 } catch (StickerPackInvalidException e
) {
56 throw new UserErrorException("Invalid sticker pack: " + e
.getMessage());