mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-09-03 23:52:05 +00:00
Read author and license information for sticker packs
This commit is contained in:
parent
0405d76ebf
commit
e2f27ad3a3
@ -10,6 +10,7 @@ import StickerPack from "../db/models/StickerPack";
|
|||||||
import Sticker from "../db/models/Sticker";
|
import Sticker from "../db/models/Sticker";
|
||||||
import { MatrixLiteClient } from "./MatrixLiteClient";
|
import { MatrixLiteClient } from "./MatrixLiteClient";
|
||||||
import { Cache, CACHE_STICKERS } from "../MemoryCache";
|
import { Cache, CACHE_STICKERS } from "../MemoryCache";
|
||||||
|
import { LicenseMap } from "../utils/LicenseMap";
|
||||||
|
|
||||||
class _MatrixStickerBot {
|
class _MatrixStickerBot {
|
||||||
|
|
||||||
@ -104,17 +105,30 @@ class _MatrixStickerBot {
|
|||||||
stickerEvents.push(stickerEvent);
|
stickerEvents.push(stickerEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const creatorId = packEvent.creatorId;
|
||||||
|
const authorName = packEvent.authorName || packEvent.creatorId;
|
||||||
|
const authorUrl = packEvent.authorUrl || `https://matrix.to/#/${packEvent.creatorId}`;
|
||||||
|
const authorIsCreator = creatorId === authorName;
|
||||||
|
|
||||||
|
let license = LicenseMap.find(packEvent.license || "");
|
||||||
|
if (!license) license = LicenseMap.find(LicenseMap.LICENSE_IMPORTED);
|
||||||
|
|
||||||
for (const pack of stickerPacks) {
|
for (const pack of stickerPacks) {
|
||||||
pack.isEnabled = true;
|
pack.isEnabled = true;
|
||||||
|
pack.trackingRoomAlias = canconicalAliasEvent.alias;
|
||||||
|
pack.name = nameEvent.name;
|
||||||
|
if (authorIsCreator) {
|
||||||
pack.authorType = "matrix";
|
pack.authorType = "matrix";
|
||||||
pack.authorReference = "https://matrix.to/#/" + packEvent.creatorId;
|
pack.authorReference = "https://matrix.to/#/" + packEvent.creatorId;
|
||||||
pack.authorName = authorDisplayName;
|
pack.authorName = authorDisplayName;
|
||||||
pack.trackingRoomAlias = canconicalAliasEvent.alias;
|
} else {
|
||||||
pack.name = nameEvent.name;
|
pack.authorType = "website";
|
||||||
|
pack.authorReference = authorUrl;
|
||||||
|
pack.authorName = authorName;
|
||||||
|
}
|
||||||
pack.description = "Matrix sticker pack created by " + authorDisplayName;
|
pack.description = "Matrix sticker pack created by " + authorDisplayName;
|
||||||
pack.license = "Imported";
|
pack.license = license.name;
|
||||||
pack.licensePath = "/licenses/general-imported.txt";
|
pack.licensePath = license.url;
|
||||||
if (stickerEvents.length > 0) pack.avatarUrl = stickerEvents[0].contentUri;
|
if (stickerEvents.length > 0) pack.avatarUrl = stickerEvents[0].contentUri;
|
||||||
await pack.save();
|
await pack.save();
|
||||||
|
|
||||||
|
30
src/utils/LicenseMap.ts
Normal file
30
src/utils/LicenseMap.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
export interface License {
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LicenseMap {
|
||||||
|
public readonly LICENSE_IMPORTED = "Imported";
|
||||||
|
|
||||||
|
private map: { [shortcode: string]: string } = {
|
||||||
|
"Imported": "/licenses/general-imported.txt",
|
||||||
|
"telegram": "/licenses/telegram-imported.txt",
|
||||||
|
"GPL v3.0": "/licenses/gpl-v3.0.txt",
|
||||||
|
"CC BY-NC-SA 4.0": "/licenses/cc_by-nc-sa_4.0.txt",
|
||||||
|
"CC BY-NC 4.0": "/licenses/cc_by-nc_4.0.txt",
|
||||||
|
"CC BY-SA 4.0": "/licenses/cc_by-sa_4.0.txt",
|
||||||
|
"CC BY 4.0": "/licenses/cc_by_4.0.txt",
|
||||||
|
};
|
||||||
|
|
||||||
|
public find(name: string): License {
|
||||||
|
for (const licenseName of Object.keys(this.map)) {
|
||||||
|
if (licenseName.toLowerCase() === name.toLowerCase()) {
|
||||||
|
return {name: licenseName, url: this.map[licenseName]};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const LicenseMap = new _LicenseMap();
|
17
web/public/licenses/cc_by-nc-sa_4.0.txt
Normal file
17
web/public/licenses/cc_by-nc-sa_4.0.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
|
||||||
|
This is a human-readable summary of (and not a substitute for) the license. (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode)
|
||||||
|
|
||||||
|
You are free to:
|
||||||
|
Share — copy and redistribute the material in any medium or format
|
||||||
|
Adapt — remix, transform, and build upon the material
|
||||||
|
|
||||||
|
The licensor cannot revoke these freedoms as long as you follow the license terms.
|
||||||
|
|
||||||
|
Under the following terms:
|
||||||
|
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
|
||||||
|
|
||||||
|
NonCommercial — You may not use the material for commercial purposes.
|
||||||
|
|
||||||
|
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
|
||||||
|
|
||||||
|
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
|
15
web/public/licenses/cc_by-sa_4.0.txt
Normal file
15
web/public/licenses/cc_by-sa_4.0.txt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
||||||
|
This is a human-readable summary of (and not a substitute for) the license. (https://creativecommons.org/licenses/by-sa/4.0/legalcode)
|
||||||
|
|
||||||
|
You are free to:
|
||||||
|
Share — copy and redistribute the material in any medium or format
|
||||||
|
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
|
||||||
|
|
||||||
|
The licensor cannot revoke these freedoms as long as you follow the license terms.
|
||||||
|
|
||||||
|
Under the following terms:
|
||||||
|
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
|
||||||
|
|
||||||
|
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
|
||||||
|
|
||||||
|
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
|
13
web/public/licenses/cc_by_4.0.txt
Normal file
13
web/public/licenses/cc_by_4.0.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
Attribution 4.0 International (CC BY 4.0)
|
||||||
|
This is a human-readable summary of (and not a substitute for) the license. (https://creativecommons.org/licenses/by/4.0/legalcode)
|
||||||
|
|
||||||
|
You are free to:
|
||||||
|
Share — copy and redistribute the material in any medium or format
|
||||||
|
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
|
||||||
|
|
||||||
|
The licensor cannot revoke these freedoms as long as you follow the license terms.
|
||||||
|
|
||||||
|
Under the following terms:
|
||||||
|
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
|
||||||
|
|
||||||
|
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
|
Loading…
Reference in New Issue
Block a user