Read author and license information for sticker packs

This commit is contained in:
Travis Ralston 2019-03-23 18:42:09 -06:00
parent 0405d76ebf
commit e2f27ad3a3
6 changed files with 95 additions and 6 deletions

View File

@ -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();

30
src/utils/LicenseMap.ts Normal file
View 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();

View 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.

View File

@ -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 additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

View 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.

View 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.