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
.OutputWriter
;
7 import org
.asamk
.signal
.PlainTextWriterImpl
;
8 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
9 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
10 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
11 import org
.asamk
.signal
.manager
.Manager
;
12 import org
.asamk
.signal
.manager
.StickerPackInvalidException
;
13 import org
.slf4j
.Logger
;
14 import org
.slf4j
.LoggerFactory
;
17 import java
.io
.IOException
;
19 public class UploadStickerPackCommand
implements LocalCommand
{
21 private final static Logger logger
= LoggerFactory
.getLogger(UploadStickerPackCommand
.class);
22 private final OutputWriter outputWriter
;
24 public UploadStickerPackCommand(final OutputWriter outputWriter
) {
25 this.outputWriter
= outputWriter
;
28 public static void attachToSubparser(final Subparser subparser
) {
29 subparser
.help("Upload a new sticker pack, consisting of a manifest file and the stickers images.");
30 subparser
.addArgument("path")
31 .help("The path of the manifest.json or a zip file containing the sticker pack you wish to upload.");
35 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
36 final var writer
= (PlainTextWriterImpl
) outputWriter
;
37 var path
= new File(ns
.getString("path"));
40 var url
= m
.uploadStickerPack(path
);
41 writer
.println("{}", url
);
42 } catch (IOException e
) {
43 throw new IOErrorException("Upload error (maybe image size too large):" + e
.getMessage());
44 } catch (StickerPackInvalidException e
) {
45 throw new UserErrorException("Invalid sticker pack: " + e
.getMessage());