Last active
May 4, 2025 01:54
-
-
Save trbt/8285640be6d6dfa4372dab19cad4fe09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* JS script to share all albums in Immich with another user. | |
* Login to Immich as admin, paste following code into Chrome DevTools console and run. | |
* Can be run multiple times, e.g. after adding new albums on changing user's role. | |
* | |
* Change the user login and assigned role to suit needs on the first 2 lines | |
*/ | |
let login = "[email protected]" | |
let role = "editor" // Possible values: [editor, viewer] | |
let users = await(await fetch("api/users", {"headers": {"Accept": "application/json"}})).json(); | |
let user = users.find(u => u.email === login) | |
if (user) { | |
let albums = await (await fetch("api/albums")).json() | |
albums.forEach(album => { | |
let albumUser = album.albumUsers.find(au => au.user.id === user.id) | |
if (albumUser === undefined) { | |
console.log("Adding user " + user.email + " to album " + album.albumName + " with role " + role) | |
fetch("api/albums/" + album.id + "/users", { | |
"headers": { | |
"Content-Type": "application/json" | |
}, | |
"body": JSON.stringify({ | |
albumUsers: [{ | |
role: role, | |
userId: user.id | |
}] | |
}), | |
"method": "PUT" | |
}) | |
} else if (albumUser.role !== role) { | |
console.log("Updating album " + album.albumName + " user " + user.email + " role from " + albumUser.role + " to " + role) | |
fetch("api/albums/" + album.id + "/user/" + user.id, { | |
"headers": { | |
"Content-Type": "application/json" | |
}, | |
"body": JSON.stringify({ | |
role: role, | |
}), | |
"method": "PUT" | |
}) | |
} else { | |
console.log("User " + user.email + " already in album " + album.albumName + " with role " + role) | |
} | |
}) | |
} else { | |
console.log("User " + user.email + " not found") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simple, effective, and works great! Thanks for creating and sharing!