Skip to content

Commit

Permalink
Mod profilepic
Browse files Browse the repository at this point in the history
  • Loading branch information
madprops committed Feb 12, 2025
1 parent dd971af commit ef27b2a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 10 deletions.
4 changes: 4 additions & 0 deletions public/static/assets/js/main/modtools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// App show superuser confirm
App.sudo = (func) => {
if (!App.superuser) {
return
}

App.show_confirm(`Run superuser command`, func)
}

Expand Down
1 change: 1 addition & 0 deletions public/static/assets/js/main/uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ App.upload_file = (args = {}) => {

obj.args.size = obj.file.size
obj.args.type = args.file.type
obj.args.user_id = args.user_id
obj.args.date = now

if (obj.args.name !== undefined) {
Expand Down
13 changes: 10 additions & 3 deletions public/static/assets/js/main/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ App.setup_user_profile = () => {
})

DOM.ev(DOM.el(`#user_profile_profilepic`), `click`, () => {
App.msg_profilepic_select.show()
App.profilepic_select()
})

DOM.ev(DOM.el(`#user_profile_audioclip`), `click`, () => {
Expand Down Expand Up @@ -272,6 +272,7 @@ App.upload_profilepic = () => {
file: App.profilepic_preview_blob,
action: `profilepic_upload`,
name: `profile.png`,
user_id: App.profilepic_id,
})

App.msg_profilepic_cropper.close()
Expand All @@ -285,7 +286,7 @@ App.setup_profilepic_select = () => {
})

DOM.ev(DOM.el(`#profilepic_select_random`), `click`, () => {
App.msg_profilepic_select.close()
App.msg_profilepmic_select.close()
App.make_random_image(`profilepic`)
})

Expand All @@ -296,7 +297,7 @@ App.setup_profilepic_select = () => {

DOM.ev(DOM.el(`#profilepic_preview_choose`), `click`, () => {
App.msg_profilepic_preview.close()
App.msg_profilepic_select.show()
App.profilepic_select()
})

DOM.ev(DOM.el(`#profilepic_preview_confirm`), `click`, () => {
Expand Down Expand Up @@ -452,4 +453,10 @@ App.audioclip_selected = (file) => {
// Get the user profile
App.get_self_user = () => {
return App.get_user_by_username(App.username)
}

// Shows the profile pic select
App.profilepic_select = (user_id = undefined) => {
App.profilepic_id = user_id
App.msg_profilepic_select.show()
}
12 changes: 12 additions & 0 deletions public/static/assets/js/main/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ App.setup_show_profile = () => {
App.msg_profile.close()
})

DOM.ev(DOM.el(`#show_profile_mod_profpic`), `click`, () => {
App.profilepic_select(App.open_profile_user_id)
App.msg_profile.close()
})

DOM.ev(DOM.el(`#show_profile_edit`), `click`, () => {
App.show_user_profile()
App.msg_profile.close()
Expand Down Expand Up @@ -708,6 +713,13 @@ App.show_profile = (username, user_id = false) => {
DOM.el(`#show_profile_info`).innerHTML = ``
DOM.hide(`#show_profile_edit`)

if (App.superuser && !same_user) {
DOM.show(`#show_profile_mod_profpic`)
}
else {
DOM.hide(`#show_profile_mod_profpic`)
}

if (user) {
let item = DOM.create(`div`)
let nicedate = App.nice_date(user.date_joined)
Expand Down
1 change: 1 addition & 0 deletions server/sockets/modules/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ module.exports = (App) => {
else if (data.action === `profilepic_upload`) {
await App.handler.upload_profilepic(socket, {
image_file: full_file,
user_id: data.user_id,
})
}
else if (data.action === `background_upload`) {
Expand Down
15 changes: 8 additions & 7 deletions server/sockets/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ module.exports = (App) => {
}

let file_name = `profilepic.png`
let container = App.i.path.join(App.vars.media_root, `user`, socket.hue.user_id)
let user_id = data.user_id || socket.hue.user_id
let container = App.i.path.join(App.vars.media_root, `user`, user_id)

if (!App.i.fs.existsSync(container)) {
App.i.fs.mkdirSync(container, {recursive: true})
Expand All @@ -137,7 +138,7 @@ module.exports = (App) => {
try {
await App.i.fsp.writeFile(path, data.image_file)
await App.strip_metadata(path)
await App.handler.do_change_profilepic(socket, file_name)
await App.handler.do_change_profilepic(socket, user_id)
}
catch (err) {
App.logger.log_error(err)
Expand All @@ -146,20 +147,20 @@ module.exports = (App) => {
}

// Completes profile image changes
App.handler.do_change_profilepic = async (socket, file_name) => {
App.handler.do_change_profilepic = async (socket, user_id) => {
let new_ver = (socket.hue.profilepic_version || 0) + 1
let userinfo = await App.db_manager.get_user([`id`, socket.hue.user_id])
let userinfo = await App.db_manager.get_user([`id`, user_id])
userinfo.profilepic_version = new_ver

await App.handler.modify_socket_properties(
socket.hue.user_id,
user_id,
{profilepic_version: new_ver},
{
method: `profilepic_changed`,
data: {
user_id: socket.hue.user_id,
username: socket.hue.username,
user_id,
profilepic_version: new_ver,
username: ``,
},
},
)
Expand Down
5 changes: 5 additions & 0 deletions server/views/main/templates/profile.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<div>Sync TV</div>
</div>

<div class="show_profile_button flex_column_center action hidden" id="show_profile_mod_profpic">
<svg class="other_icon profile_icon"><use href="#icon_user"></use></svg>
<div>Mod: Change Pic</div>
</div>

<div class="show_profile_button flex_column_center action" id="show_profile_edit">
<svg class="other_icon profile_icon"><use href="#icon_user"></use></svg>
<div>Edit Profile</div>
Expand Down

0 comments on commit ef27b2a

Please sign in to comment.