mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Add optional content type to json sticker pack manifest
This commit is contained in:
parent
0b2d37fe68
commit
f40c351662
3 changed files with 35 additions and 5 deletions
|
@ -25,5 +25,8 @@ public class JsonStickerPack {
|
|||
|
||||
@JsonProperty
|
||||
public String file;
|
||||
|
||||
@JsonProperty
|
||||
public String contentType;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,12 @@ import org.whispersystems.libsignal.util.Pair;
|
|||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceStickerManifestUpload;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
|
@ -54,7 +56,9 @@ public class StickerUtils {
|
|||
throw new StickerPackInvalidException("Could not find find " + sticker.file);
|
||||
}
|
||||
|
||||
var contentType = Utils.getFileMimeType(new File(sticker.file), null);
|
||||
var contentType = sticker.contentType != null && !sticker.contentType.isEmpty()
|
||||
? sticker.contentType
|
||||
: getContentType(rootPath, zip, sticker.file);
|
||||
var stickerInfo = new SignalServiceStickerManifestUpload.StickerInfo(data.first(),
|
||||
data.second(),
|
||||
Optional.fromNullable(sticker.emoji).or(""),
|
||||
|
@ -75,7 +79,9 @@ public class StickerUtils {
|
|||
throw new StickerPackInvalidException("Could not find find " + pack.cover.file);
|
||||
}
|
||||
|
||||
var contentType = Utils.getFileMimeType(new File(pack.cover.file), null);
|
||||
var contentType = pack.cover.contentType != null && !pack.cover.contentType.isEmpty()
|
||||
? pack.cover.contentType
|
||||
: getContentType(rootPath, zip, pack.cover.file);
|
||||
cover = new SignalServiceStickerManifestUpload.StickerInfo(data.first(),
|
||||
data.second(),
|
||||
Optional.fromNullable(pack.cover.emoji).or(""),
|
||||
|
@ -107,4 +113,17 @@ public class StickerUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private static String getContentType(
|
||||
final String rootPath, final ZipFile zip, final String subfile
|
||||
) throws IOException {
|
||||
if (zip != null) {
|
||||
final var entry = zip.getEntry(subfile);
|
||||
try (InputStream bufferedStream = new BufferedInputStream(zip.getInputStream(entry))) {
|
||||
return URLConnection.guessContentTypeFromStream(bufferedStream);
|
||||
}
|
||||
} else {
|
||||
final var file = new File(rootPath, subfile);
|
||||
return Utils.getFileMimeType(file, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -412,7 +412,13 @@ group lists.
|
|||
|
||||
=== uploadStickerPack
|
||||
|
||||
Upload a new sticker pack, consisting of a manifest file and the stickers in WebP format (maximum size for a sticker file is 100KiB).
|
||||
Upload a new sticker pack, consisting of a manifest file and the sticker images.
|
||||
Images must conform to the following specification: (see https://support.signal.org/hc/en-us/articles/360031836512-Stickers#sticker_reqs )
|
||||
- Static stickers in PNG or WebP format
|
||||
- Animated stickers in APNG format,
|
||||
- Maximum file size for a sticker file is 300KiB
|
||||
- Image resolution of 512 x 512 px
|
||||
|
||||
The required manifest.json has the following format:
|
||||
|
||||
[source,json]
|
||||
|
@ -421,12 +427,14 @@ The required manifest.json has the following format:
|
|||
"title": "<STICKER_PACK_TITLE>",
|
||||
"author": "<STICKER_PACK_AUTHOR>",
|
||||
"cover": { // Optional cover, by default the first sticker is used as cover
|
||||
"file": "<name of webp file, mandatory>",
|
||||
"file": "<name of image file, mandatory>",
|
||||
"contentType": "<optional>",
|
||||
"emoji": "<optional>"
|
||||
},
|
||||
"stickers": [
|
||||
{
|
||||
"file": "<name of webp file, mandatory>",
|
||||
"file": "<name of image file, mandatory>",
|
||||
"contentType": "<optional>",
|
||||
"emoji": "<optional>"
|
||||
}
|
||||
...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue