From e2f27ad3a38fc8a72337113c17ec02088e203fc3 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 23 Mar 2019 18:42:09 -0600 Subject: [PATCH] Read author and license information for sticker packs --- src/matrix/MatrixStickerBot.ts | 24 +++++++++++++++----- src/utils/LicenseMap.ts | 30 +++++++++++++++++++++++++ web/public/licenses/cc_by-nc-sa_4.0.txt | 17 ++++++++++++++ web/public/licenses/cc_by-nc_4.0.txt | 2 +- web/public/licenses/cc_by-sa_4.0.txt | 15 +++++++++++++ web/public/licenses/cc_by_4.0.txt | 13 +++++++++++ 6 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 src/utils/LicenseMap.ts create mode 100644 web/public/licenses/cc_by-nc-sa_4.0.txt create mode 100644 web/public/licenses/cc_by-sa_4.0.txt create mode 100644 web/public/licenses/cc_by_4.0.txt diff --git a/src/matrix/MatrixStickerBot.ts b/src/matrix/MatrixStickerBot.ts index 081d523..fd9fb42 100644 --- a/src/matrix/MatrixStickerBot.ts +++ b/src/matrix/MatrixStickerBot.ts @@ -10,6 +10,7 @@ import StickerPack from "../db/models/StickerPack"; import Sticker from "../db/models/Sticker"; import { MatrixLiteClient } from "./MatrixLiteClient"; import { Cache, CACHE_STICKERS } from "../MemoryCache"; +import { LicenseMap } from "../utils/LicenseMap"; class _MatrixStickerBot { @@ -104,17 +105,30 @@ class _MatrixStickerBot { 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) { pack.isEnabled = true; - pack.authorType = "matrix"; - pack.authorReference = "https://matrix.to/#/" + packEvent.creatorId; - pack.authorName = authorDisplayName; pack.trackingRoomAlias = canconicalAliasEvent.alias; pack.name = nameEvent.name; + if (authorIsCreator) { + pack.authorType = "matrix"; + pack.authorReference = "https://matrix.to/#/" + packEvent.creatorId; + pack.authorName = authorDisplayName; + } else { + pack.authorType = "website"; + pack.authorReference = authorUrl; + pack.authorName = authorName; + } pack.description = "Matrix sticker pack created by " + authorDisplayName; - pack.license = "Imported"; - pack.licensePath = "/licenses/general-imported.txt"; + pack.license = license.name; + pack.licensePath = license.url; if (stickerEvents.length > 0) pack.avatarUrl = stickerEvents[0].contentUri; await pack.save(); diff --git a/src/utils/LicenseMap.ts b/src/utils/LicenseMap.ts new file mode 100644 index 0000000..c448314 --- /dev/null +++ b/src/utils/LicenseMap.ts @@ -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(); \ No newline at end of file diff --git a/web/public/licenses/cc_by-nc-sa_4.0.txt b/web/public/licenses/cc_by-nc-sa_4.0.txt new file mode 100644 index 0000000..e66ae34 --- /dev/null +++ b/web/public/licenses/cc_by-nc-sa_4.0.txt @@ -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. diff --git a/web/public/licenses/cc_by-nc_4.0.txt b/web/public/licenses/cc_by-nc_4.0.txt index d38aef6..c74fcaa 100644 --- a/web/public/licenses/cc_by-nc_4.0.txt +++ b/web/public/licenses/cc_by-nc_4.0.txt @@ -12,4 +12,4 @@ Attribution — You must give appropriate credit, provide a link to the license, NonCommercial — You may not use the material for commercial purposes. -No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. \ No newline at end of file +No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. diff --git a/web/public/licenses/cc_by-sa_4.0.txt b/web/public/licenses/cc_by-sa_4.0.txt new file mode 100644 index 0000000..c5cba83 --- /dev/null +++ b/web/public/licenses/cc_by-sa_4.0.txt @@ -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. diff --git a/web/public/licenses/cc_by_4.0.txt b/web/public/licenses/cc_by_4.0.txt new file mode 100644 index 0000000..f86a108 --- /dev/null +++ b/web/public/licenses/cc_by_4.0.txt @@ -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.