Remove usage of tiley (#4406)

* First pass

* Mooarrr

* lint

* snapshots
This commit is contained in:
Tom Moor
2022-11-08 17:12:22 -08:00
committed by GitHub
parent 920b58c006
commit 587f062677
38 changed files with 169 additions and 177 deletions

View File

@@ -40,7 +40,6 @@ async function teamCreator({
// one via ClearBit, or fallback to colored initials in worst case scenario
if (!avatarUrl || !avatarUrl.startsWith("http")) {
avatarUrl = await generateAvatarUrl({
name,
domain,
id: subdomain,
});

View File

@@ -329,13 +329,6 @@ export class Environment {
*/
public RELEASE = this.toOptionalString(process.env.RELEASE);
/**
* An optional host from which to load default avatars.
*/
@IsUrl()
public DEFAULT_AVATAR_HOST =
process.env.DEFAULT_AVATAR_HOST ?? "https://tiley.herokuapp.com";
/**
* A Google Analytics tracking ID, only v3 supported at this time.
*/

View File

@@ -24,7 +24,6 @@ import { CollectionPermission, TeamPreference } from "@shared/types";
import { getBaseDomain, RESERVED_SUBDOMAINS } from "@shared/utils/domains";
import env from "@server/env";
import DeleteAttachmentTask from "@server/queues/tasks/DeleteAttachmentTask";
import { generateAvatarUrl } from "@server/utils/avatars";
import parseAttachmentIds from "@server/utils/parseAttachmentIds";
import Attachment from "./Attachment";
import AuthenticationProvider from "./AuthenticationProvider";
@@ -94,8 +93,20 @@ class Team extends ParanoidModel {
@AllowNull
@IsUrl
@Length({ max: 4096, msg: "avatarUrl must be 4096 characters or less" })
@Column
avatarUrl: string | null;
@Column(DataType.STRING)
get avatarUrl() {
const original = this.getDataValue("avatarUrl");
if (original && !original.startsWith("https://tiley.herokuapp.com")) {
return original;
}
return null;
}
set avatarUrl(value: string | null) {
this.setDataValue("avatarUrl", value);
}
@Default(true)
@Column
@@ -163,16 +174,6 @@ class Team extends ParanoidModel {
return url.href.replace(/\/$/, "");
}
get logoUrl() {
return (
this.avatarUrl ||
generateAvatarUrl({
id: this.id,
name: this.name,
})
);
}
/**
* Preferences that decide behavior for the team.
*

View File

@@ -180,17 +180,11 @@ class User extends ParanoidModel {
get avatarUrl() {
const original = this.getDataValue("avatarUrl");
if (original) {
if (original && !original.startsWith("https://tiley.herokuapp.com")) {
return original;
}
const color = this.color.replace(/^#/, "");
const initial = this.name ? this.name[0] : "?";
const hash = crypto
.createHash("md5")
.update(this.email || "")
.digest("hex");
return `${env.DEFAULT_AVATAR_HOST}/avatar/${hash}/${initial}.png?c=${color}`;
return null;
}
set avatarUrl(value: string | null) {

View File

@@ -2,7 +2,7 @@
exports[`presents a user 1`] = `
Object {
"avatarUrl": "https://tiley.herokuapp.com/avatar/d41d8cd98f00b204e9800998ecf8427e/T.png?c=FF5C80",
"avatarUrl": null,
"color": "#FF5C80",
"createdAt": undefined,
"id": "123",
@@ -17,7 +17,7 @@ Object {
exports[`presents a user without slack data 1`] = `
Object {
"avatarUrl": "https://tiley.herokuapp.com/avatar/d41d8cd98f00b204e9800998ecf8427e/T.png?c=FF5C80",
"avatarUrl": null,
"color": "#FF5C80",
"createdAt": undefined,
"id": "123",

View File

@@ -4,7 +4,7 @@ export default function present(team: Team, isSignedIn = false) {
return {
id: team.id,
name: team.name,
avatarUrl: team.logoUrl,
avatarUrl: team.avatarUrl,
url: team.url,
isSignedIn,
};

View File

@@ -4,7 +4,7 @@ export default function present(team: Team) {
return {
id: team.id,
name: team.name,
avatarUrl: team.logoUrl,
avatarUrl: team.avatarUrl,
sharing: team.sharing,
memberCollectionCreate: team.memberCollectionCreate,
collaborativeEditing: team.collaborativeEditing,

View File

@@ -3,7 +3,7 @@
exports[`#users.activate should activate a suspended user 1`] = `
Object {
"data": Object {
"avatarUrl": "https://tiley.herokuapp.com/avatar/111d68d06e2d317b5a59c2c6c5bad808/U.png?c=e600e0",
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
@@ -59,7 +59,7 @@ Object {
exports[`#users.demote should demote an admin 1`] = `
Object {
"data": Object {
"avatarUrl": "https://tiley.herokuapp.com/avatar/111d68d06e2d317b5a59c2c6c5bad808/U.png?c=e600e0",
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
@@ -97,7 +97,7 @@ Object {
exports[`#users.demote should demote an admin to member 1`] = `
Object {
"data": Object {
"avatarUrl": "https://tiley.herokuapp.com/avatar/111d68d06e2d317b5a59c2c6c5bad808/U.png?c=e600e0",
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
@@ -135,7 +135,7 @@ Object {
exports[`#users.demote should demote an admin to viewer 1`] = `
Object {
"data": Object {
"avatarUrl": "https://tiley.herokuapp.com/avatar/111d68d06e2d317b5a59c2c6c5bad808/U.png?c=e600e0",
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
@@ -191,7 +191,7 @@ Object {
exports[`#users.promote should promote a new admin 1`] = `
Object {
"data": Object {
"avatarUrl": "https://tiley.herokuapp.com/avatar/111d68d06e2d317b5a59c2c6c5bad808/U.png?c=e600e0",
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
@@ -256,7 +256,7 @@ Object {
exports[`#users.suspend should suspend an user 1`] = `
Object {
"data": Object {
"avatarUrl": "https://tiley.herokuapp.com/avatar/111d68d06e2d317b5a59c2c6c5bad808/U.png?c=e600e0",
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",

View File

@@ -93,7 +93,7 @@ export async function signIn(
...existing,
[team.id]: {
name: team.name,
logoUrl: team.logoUrl,
logoUrl: team.avatarUrl,
url: team.url,
},
})

View File

@@ -4,43 +4,6 @@ it("should return clearbit url if available", async () => {
const url = await generateAvatarUrl({
id: "google",
domain: "google.com",
name: "Google",
});
expect(url).toBe("https://logo.clearbit.com/google.com");
});
it("should return tiley url if clearbit unavailable", async () => {
const url = await generateAvatarUrl({
id: "invalid",
domain: "example.invalid",
name: "Invalid",
});
expect(url).toBe(
"https://tiley.herokuapp.com/avatar/f1234d75178d892a133a410355a5a990cf75d2f33eba25d575943d4df632f3a4/I.png"
);
});
it("should return tiley url if domain not provided", async () => {
const url = await generateAvatarUrl({
id: "google",
name: "Google",
});
expect(url).toBe(
"https://tiley.herokuapp.com/avatar/bbdefa2950f49882f295b1285d4fa9dec45fc4144bfb07ee6acc68762d12c2e3/G.png"
);
});
it("should return tiley url if name not provided", async () => {
const url = await generateAvatarUrl({
id: "google",
});
expect(url).toBe(
"https://tiley.herokuapp.com/avatar/bbdefa2950f49882f295b1285d4fa9dec45fc4144bfb07ee6acc68762d12c2e3/U.png"
);
});
it("should return tiley url with encoded name", async () => {
const url = await generateAvatarUrl({
id: "google",
name: "株",
});
expect(url).toBe(
"https://tiley.herokuapp.com/avatar/bbdefa2950f49882f295b1285d4fa9dec45fc4144bfb07ee6acc68762d12c2e3/%E6%A0%AA.png"
);
});

View File

@@ -1,21 +1,17 @@
import crypto from "crypto";
import fetch from "fetch-with-proxy";
import env from "@server/env";
export async function generateAvatarUrl({
id,
domain,
name = "Unknown",
}: {
id: string;
domain?: string;
name?: string;
}) {
// attempt to get logo from Clearbit API. If one doesn't exist then
// fall back to using tiley to generate a placeholder logo
const hash = crypto.createHash("sha256");
hash.update(id);
const hashedId = hash.digest("hex");
let cbResponse, cbUrl;
if (domain) {
@@ -28,8 +24,5 @@ export async function generateAvatarUrl({
}
}
const tileyUrl = `${
env.DEFAULT_AVATAR_HOST
}/avatar/${hashedId}/${encodeURIComponent(name[0])}.png`;
return cbUrl && cbResponse && cbResponse.status === 200 ? cbUrl : tileyUrl;
return cbUrl && cbResponse && cbResponse.status === 200 ? cbUrl : null;
}

View File

@@ -6,7 +6,6 @@ import fetch from "fetch-with-proxy";
import { compact } from "lodash";
import { useAgent } from "request-filtering-agent";
import { v4 as uuidv4 } from "uuid";
import env from "@server/env";
import Logger from "@server/logging/Logger";
const AWS_S3_ACCELERATE_URL = process.env.AWS_S3_ACCELERATE_URL;
@@ -184,11 +183,7 @@ export const uploadToS3FromUrl = async (
acl: string
) => {
const endpoint = publicS3Endpoint(true);
if (
url.startsWith("/api") ||
url.startsWith(endpoint) ||
url.startsWith(env.DEFAULT_AVATAR_HOST)
) {
if (url.startsWith("/api") || url.startsWith(endpoint)) {
return;
}