Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commands for upper staff to add custom avatars #5515

Closed
wants to merge 2 commits into from
Closed

Add commands for upper staff to add custom avatars #5515

wants to merge 2 commits into from

Conversation

mia-pi-git
Copy link
Member

I was told basing off of other's code was fine if i credited as so, please excuse me if i'm wrong otherwise.

I was told basing off of other's code was fine if i credited as so, please excuse me if i'm wrong otherwise.
@HoeenCoder HoeenCoder self-requested a review May 31, 2019 20:41
Copy link
Contributor

@scheibo scheibo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick first pass. Given the code you're attempting to get included upstream is also MIT licensed and youve included attribution I feel its OK, but including @CreaturePhil in the discussion to make sure he's aware and can weigh in.

Ultimately, @Zarel is going to need to weigh in on whether the feature is desirable in the first place, as he's currently the only one uploading avatars to the best of my knowledge, and I believe that he'd probably want to have every avatar run by him anyway to be able to maintain quality standards and visual cohesiveness, so I don't know how much of an impact this would be on the custom avatar process because Zarel's attention would be required either way.

(Thank you opening a PR though! Worth starting a discussion over)

server/chat-plugins/customavatars.js Show resolved Hide resolved
server/chat-plugins/customavatars.js Outdated Show resolved Hide resolved
server/chat-plugins/customavatars.js Outdated Show resolved Hide resolved
server/chat-plugins/customavatars.js Outdated Show resolved Hide resolved
server/chat-plugins/customavatars.js Show resolved Hide resolved
let type = response.headers['content-type'].split('/');
if (type[0] !== 'image') return;

response.pipe(FS(AVATAR_PATH + name + extension).createWriteStream());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the string concatenations in this file can be template strings instead

const https = require('https');

function downloadImage(image_url, name, extension) {
let req = https.get(image_url, res => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be returning a promise

});
});
req.on('error', e => {
console.error(e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this is the correct error handling mechanism

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to throw the error to crashlogger in hindsight.

I need to review the plugin as a whole when I have time, haven't done much other than offer advice on a few issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error handling and logging seems to be quite badly implemented.

@mia-pi-git
Copy link
Member Author

mia-pi-git commented May 31, 2019

resolving as i'm fixing, will commit once everything's done so it's less spammy.
e: gotta do stuff for the rest of today irl so i'll commit what i have for review.

forEach is also WIP, but is taking longer.

let name = toID(parts[0]);
let avatarUrl = parts[1];
if (!/^https?:\/\//i.test(avatarUrl)) avatarUrl = 'http://' + avatarUrl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URLs don't necessarily end in the extension of the actual file they point at

server/chat-plugins/customavatars.js Show resolved Hide resolved
*/
'use strict';

/** @type {typeof import('../../lib/fs').FS} */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the wrong place, it should be above the importing of 'FS'.

server/chat-plugins/customavatars.js Show resolved Hide resolved
if (err) console.log("Error loading custom avatars: " + err);
if (!files) files = [];
files
.filter(file => VALID_EXTENSIONS.includes(path.extname(file)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably blacklist __proto__ and constructor

@Slayer95
Copy link
Contributor

Slayer95 commented Jun 1, 2019

This implementation uses node-static, so these commands should be disabled for Config.disablenodestatic == true.

Also, since it might not be obvious for those who find this PR:
This implementation is invalid for the Smogon University server.

let type = response.headers['content-type'].split('/');
if (type[0] !== 'image') return;

response.pipe(fs(AVATAR_PATH + name + extension).createWriteStream());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be returning a promise

Resolve the promise on finish event of the fs write stream.

@Zarel
Copy link
Member

Zarel commented Jun 1, 2019

Ultimately, @Zarel is going to need to weigh in on whether the feature is desirable in the first place, as he's currently the only one uploading avatars to the best of my knowledge, and I believe that he'd probably want to have every avatar run by him anyway to be able to maintain quality standards and visual cohesiveness, so I don't know how much of an impact this would be on the custom avatar process because Zarel's attention would be required either way.

This is purely for side servers, which are allowed to set their own custom avatars without oversight.

The main server already uses a completely different mechanism for custom avatars (which is what Slayer95 means by "this implementation is invalid for the Smogon server"), mainly because we have access to more durable avatar storage (which lets our custom avatars be visible in replays).

For side servers, yes, I'm completely OK with this, once the code quality issues get sorted out.

@Zarel
Copy link
Member

Zarel commented Nov 28, 2019

This looks abandoned. Feel free to reopen if you're still planning to work on this, but otherwise I've moved it to #2444.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants