generated from nhcarrigan/template
Compare commits
6 Commits
v1.1.0
..
e6b6131134
| Author | SHA1 | Date | |
|---|---|---|---|
| e6b6131134 | |||
| d74a342f63 | |||
| b781034fce | |||
| f40f917bc5 | |||
| 1fd2086afe | |||
| 3668a67a62 |
@@ -102,53 +102,6 @@ const authRoutes: FastifyPluginAsync = async (app) => {
|
||||
request
|
||||
);
|
||||
|
||||
// Assign library member role if user is in Discord server but doesn't have it
|
||||
const libraryRoleId = process.env.LIBRARY_ROLE_ID;
|
||||
if (inDiscord && guildId && libraryRoleId) {
|
||||
try {
|
||||
const memberResponse = await fetch(
|
||||
`https://discord.com/api/users/@me/guilds/${guildId}/member`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${tokenResult.token.access_token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (memberResponse.ok) {
|
||||
const memberData = await memberResponse.json() as { roles: string[] };
|
||||
const hasLibraryRole = memberData.roles.includes(libraryRoleId);
|
||||
|
||||
if (!hasLibraryRole) {
|
||||
const botToken = process.env.DISCORD_BOT_TOKEN;
|
||||
if (botToken) {
|
||||
const assignRoleResponse = await fetch(
|
||||
`https://discord.com/api/v10/guilds/${guildId}/members/${userData.id}/roles/${libraryRoleId}`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Bot ${botToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (assignRoleResponse.ok || assignRoleResponse.status === 204) {
|
||||
app.log.info(`Assigned library role to user ${user.username} (${user.id})`);
|
||||
} else {
|
||||
app.log.error(
|
||||
`Failed to assign library role to user ${user.username}: ${assignRoleResponse.status}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Don't fail the login if role assignment fails
|
||||
app.log.error({ err: error }, "Error assigning library role");
|
||||
}
|
||||
}
|
||||
|
||||
// Set signed cookies and redirect to frontend
|
||||
reply
|
||||
.setCookie("auth-token", accessToken, {
|
||||
|
||||
@@ -244,8 +244,8 @@ import { Suggestion, SuggestionStatus, SuggestionEntity, CreateGameDto, UpdateGa
|
||||
<app-game-form
|
||||
mode="add"
|
||||
[initialData]="getGameInitialData(editingSuggestion()!)"
|
||||
(formSubmit)="saveGameFromSuggestion($event)"
|
||||
(formCancel)="closeEditModal()"
|
||||
(save)="saveGameFromSuggestion($event)"
|
||||
(cancel)="closeEditModal()"
|
||||
></app-game-form>
|
||||
} @else if (editingSuggestion()!.entityType === SuggestionEntity.book) {
|
||||
<h3>Review & Edit Book Before Accepting</h3>
|
||||
@@ -253,8 +253,8 @@ import { Suggestion, SuggestionStatus, SuggestionEntity, CreateGameDto, UpdateGa
|
||||
<app-book-form
|
||||
mode="add"
|
||||
[initialData]="getBookInitialData(editingSuggestion()!)"
|
||||
(formSubmit)="saveBookFromSuggestion($event)"
|
||||
(formCancel)="closeEditModal()"
|
||||
(save)="saveBookFromSuggestion($event)"
|
||||
(cancel)="closeEditModal()"
|
||||
></app-book-form>
|
||||
} @else if (editingSuggestion()!.entityType === SuggestionEntity.music) {
|
||||
<h3>Review & Edit Music Before Accepting</h3>
|
||||
@@ -262,8 +262,8 @@ import { Suggestion, SuggestionStatus, SuggestionEntity, CreateGameDto, UpdateGa
|
||||
<app-music-form
|
||||
mode="add"
|
||||
[initialData]="getMusicInitialData(editingSuggestion()!)"
|
||||
(formSubmit)="saveMusicFromSuggestion($event)"
|
||||
(formCancel)="closeEditModal()"
|
||||
(save)="saveMusicFromSuggestion($event)"
|
||||
(cancel)="closeEditModal()"
|
||||
></app-music-form>
|
||||
} @else if (editingSuggestion()!.entityType === SuggestionEntity.show) {
|
||||
<h3>Review & Edit Show Before Accepting</h3>
|
||||
@@ -271,8 +271,8 @@ import { Suggestion, SuggestionStatus, SuggestionEntity, CreateGameDto, UpdateGa
|
||||
<app-show-form
|
||||
mode="add"
|
||||
[initialData]="getShowInitialData(editingSuggestion()!)"
|
||||
(formSubmit)="saveShowFromSuggestion($event)"
|
||||
(formCancel)="closeEditModal()"
|
||||
(save)="saveShowFromSuggestion($event)"
|
||||
(cancel)="closeEditModal()"
|
||||
></app-show-form>
|
||||
} @else if (editingSuggestion()!.entityType === SuggestionEntity.manga) {
|
||||
<h3>Review & Edit Manga Before Accepting</h3>
|
||||
@@ -280,8 +280,8 @@ import { Suggestion, SuggestionStatus, SuggestionEntity, CreateGameDto, UpdateGa
|
||||
<app-manga-form
|
||||
mode="add"
|
||||
[initialData]="getMangaInitialData(editingSuggestion()!)"
|
||||
(formSubmit)="saveMangaFromSuggestion($event)"
|
||||
(formCancel)="closeEditModal()"
|
||||
(save)="saveMangaFromSuggestion($event)"
|
||||
(cancel)="closeEditModal()"
|
||||
></app-manga-form>
|
||||
} @else if (editingSuggestion()!.entityType === SuggestionEntity.art) {
|
||||
<h3>Review & Edit Art Before Accepting</h3>
|
||||
@@ -289,8 +289,8 @@ import { Suggestion, SuggestionStatus, SuggestionEntity, CreateGameDto, UpdateGa
|
||||
<app-art-form
|
||||
mode="add"
|
||||
[initialData]="getArtInitialData(editingSuggestion()!)"
|
||||
(formSubmit)="saveArtFromSuggestion($event)"
|
||||
(formCancel)="closeEditModal()"
|
||||
(save)="saveArtFromSuggestion($event)"
|
||||
(cancel)="closeEditModal()"
|
||||
></app-art-form>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import { Art, Comment, UpdateArtDto } from '@library/shared-types';
|
||||
<app-art-form
|
||||
mode="edit"
|
||||
[art]="art()!"
|
||||
(formSubmit)="saveEdit($event)"
|
||||
(formCancel)="cancelEdit()"
|
||||
(save)="saveEdit($event)"
|
||||
(cancel)="cancelEdit()"
|
||||
></app-art-form>
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ import { Book, Comment, BookStatus, UpdateBookDto } from '@library/shared-types'
|
||||
<app-book-form
|
||||
mode="edit"
|
||||
[book]="book()!"
|
||||
(formSubmit)="saveEdit($event)"
|
||||
(formCancel)="cancelEdit()"
|
||||
(save)="saveEdit($event)"
|
||||
(cancel)="cancelEdit()"
|
||||
></app-book-form>
|
||||
}
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ import { Game, Comment, GameStatus, UpdateGameDto } from '@library/shared-types'
|
||||
<app-game-form
|
||||
mode="edit"
|
||||
[game]="game()!"
|
||||
(formSubmit)="saveEdit($event)"
|
||||
(formCancel)="cancelEdit()"
|
||||
(save)="saveEdit($event)"
|
||||
(cancel)="cancelEdit()"
|
||||
></app-game-form>
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ import { Manga, Comment, MangaStatus, UpdateMangaDto } from '@library/shared-typ
|
||||
<app-manga-form
|
||||
mode="edit"
|
||||
[manga]="manga()!"
|
||||
(formSubmit)="saveEdit($event)"
|
||||
(formCancel)="cancelEdit()"
|
||||
(save)="saveEdit($event)"
|
||||
(cancel)="cancelEdit()"
|
||||
></app-manga-form>
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ import { Music, Comment, MusicStatus, MusicType, UpdateMusicDto } from '@library
|
||||
<app-music-form
|
||||
mode="edit"
|
||||
[music]="music()!"
|
||||
(formSubmit)="saveEdit($event)"
|
||||
(formCancel)="cancelEdit()"
|
||||
(save)="saveEdit($event)"
|
||||
(cancel)="cancelEdit()"
|
||||
></app-music-form>
|
||||
}
|
||||
|
||||
|
||||
@@ -290,8 +290,8 @@ export class ArtFormComponent implements OnInit {
|
||||
@Input() mode: 'add' | 'edit' = 'add';
|
||||
@Input() art?: Art;
|
||||
@Input() initialData?: Partial<CreateArtDto>;
|
||||
@Output() formSubmit = new EventEmitter<CreateArtDto | UpdateArtDto>();
|
||||
@Output() formCancel = new EventEmitter<void>();
|
||||
@Output() save = new EventEmitter<CreateArtDto | UpdateArtDto>();
|
||||
@Output() cancel = new EventEmitter<void>();
|
||||
|
||||
formData: Partial<CreateArtDto | UpdateArtDto> = {
|
||||
tags: [],
|
||||
@@ -396,10 +396,10 @@ export class ArtFormComponent implements OnInit {
|
||||
...this.formData as CreateArtDto | UpdateArtDto
|
||||
};
|
||||
|
||||
this.formSubmit.emit(data);
|
||||
this.save.emit(data);
|
||||
}
|
||||
|
||||
onCancel() {
|
||||
this.formCancel.emit();
|
||||
this.cancel.emit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,8 +404,8 @@ export class BookFormComponent implements OnInit {
|
||||
@Input() mode: 'add' | 'edit' = 'add';
|
||||
@Input() book?: Book;
|
||||
@Input() initialData?: Partial<CreateBookDto>;
|
||||
@Output() formSubmit = new EventEmitter<CreateBookDto | UpdateBookDto>();
|
||||
@Output() formCancel = new EventEmitter<void>();
|
||||
@Output() save = new EventEmitter<CreateBookDto | UpdateBookDto>();
|
||||
@Output() cancel = new EventEmitter<void>();
|
||||
|
||||
BookStatus = BookStatus;
|
||||
|
||||
@@ -534,10 +534,10 @@ export class BookFormComponent implements OnInit {
|
||||
dateFinished: this.formData.dateFinished ? new Date(this.formData.dateFinished) : undefined
|
||||
};
|
||||
|
||||
this.formSubmit.emit(data);
|
||||
this.save.emit(data);
|
||||
}
|
||||
|
||||
onCancel() {
|
||||
this.formCancel.emit();
|
||||
this.cancel.emit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,8 +392,8 @@ export class GameFormComponent implements OnInit {
|
||||
@Input() mode: 'add' | 'edit' = 'add';
|
||||
@Input() game?: Game;
|
||||
@Input() initialData?: Partial<CreateGameDto>;
|
||||
@Output() formSubmit = new EventEmitter<CreateGameDto | UpdateGameDto>();
|
||||
@Output() formCancel = new EventEmitter<void>();
|
||||
@Output() save = new EventEmitter<CreateGameDto | UpdateGameDto>();
|
||||
@Output() cancel = new EventEmitter<void>();
|
||||
|
||||
GameStatus = GameStatus;
|
||||
|
||||
@@ -522,10 +522,10 @@ export class GameFormComponent implements OnInit {
|
||||
dateFinished: this.formData.dateFinished ? new Date(this.formData.dateFinished) : undefined
|
||||
};
|
||||
|
||||
this.formSubmit.emit(data);
|
||||
this.save.emit(data);
|
||||
}
|
||||
|
||||
onCancel() {
|
||||
this.formCancel.emit();
|
||||
this.cancel.emit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,8 +370,8 @@ export class MangaFormComponent implements OnInit {
|
||||
@Input() mode: 'add' | 'edit' = 'add';
|
||||
@Input() manga?: Manga;
|
||||
@Input() initialData?: Partial<CreateMangaDto>;
|
||||
@Output() formSubmit = new EventEmitter<CreateMangaDto | UpdateMangaDto>();
|
||||
@Output() formCancel = new EventEmitter<void>();
|
||||
@Output() save = new EventEmitter<CreateMangaDto | UpdateMangaDto>();
|
||||
@Output() cancel = new EventEmitter<void>();
|
||||
|
||||
MangaStatus = MangaStatus;
|
||||
|
||||
@@ -497,10 +497,10 @@ export class MangaFormComponent implements OnInit {
|
||||
dateFinished: this.formData.dateFinished ? new Date(this.formData.dateFinished) : undefined
|
||||
};
|
||||
|
||||
this.formSubmit.emit(data);
|
||||
this.save.emit(data);
|
||||
}
|
||||
|
||||
onCancel() {
|
||||
this.formCancel.emit();
|
||||
this.cancel.emit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,8 +379,8 @@ export class MusicFormComponent implements OnInit {
|
||||
@Input() mode: 'add' | 'edit' = 'add';
|
||||
@Input() music?: Music;
|
||||
@Input() initialData?: Partial<CreateMusicDto>;
|
||||
@Output() formSubmit = new EventEmitter<CreateMusicDto | UpdateMusicDto>();
|
||||
@Output() formCancel = new EventEmitter<void>();
|
||||
@Output() save = new EventEmitter<CreateMusicDto | UpdateMusicDto>();
|
||||
@Output() cancel = new EventEmitter<void>();
|
||||
|
||||
MusicStatus = MusicStatus;
|
||||
MusicType = MusicType;
|
||||
@@ -509,10 +509,10 @@ export class MusicFormComponent implements OnInit {
|
||||
dateFinished: this.formData.dateFinished ? new Date(this.formData.dateFinished) : undefined
|
||||
};
|
||||
|
||||
this.formSubmit.emit(data);
|
||||
this.save.emit(data);
|
||||
}
|
||||
|
||||
onCancel() {
|
||||
this.formCancel.emit();
|
||||
this.cancel.emit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,8 +368,8 @@ export class ShowFormComponent implements OnInit {
|
||||
@Input() mode: 'add' | 'edit' = 'add';
|
||||
@Input() show?: Show;
|
||||
@Input() initialData?: Partial<CreateShowDto>;
|
||||
@Output() formSubmit = new EventEmitter<CreateShowDto | UpdateShowDto>();
|
||||
@Output() formCancel = new EventEmitter<void>();
|
||||
@Output() save = new EventEmitter<CreateShowDto | UpdateShowDto>();
|
||||
@Output() cancel = new EventEmitter<void>();
|
||||
|
||||
ShowStatus = ShowStatus;
|
||||
ShowType = ShowType;
|
||||
@@ -497,10 +497,10 @@ export class ShowFormComponent implements OnInit {
|
||||
dateFinished: this.formData.dateFinished ? new Date(this.formData.dateFinished) : undefined
|
||||
};
|
||||
|
||||
this.formSubmit.emit(data);
|
||||
this.save.emit(data);
|
||||
}
|
||||
|
||||
onCancel() {
|
||||
this.formCancel.emit();
|
||||
this.cancel.emit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import { Show, Comment, ShowStatus, ShowType, UpdateShowDto } from '@library/sha
|
||||
<app-show-form
|
||||
mode="edit"
|
||||
[show]="show()!"
|
||||
(formSubmit)="saveEdit($event)"
|
||||
(formCancel)="cancelEdit()"
|
||||
(save)="saveEdit($event)"
|
||||
(cancel)="cancelEdit()"
|
||||
></app-show-form>
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@ DISCORD_GUILD_ID="op://Environment Variables - Naomi/Library/discord server id"
|
||||
SPONSOR_ROLE_ID="op://Environment Variables - Naomi/Library/sponsor role id"
|
||||
MOD_ROLE_ID="op://Environment Variables - Naomi/Library/mod role id"
|
||||
STAFF_ROLE_ID="op://Environment Variables - Naomi/Library/staff role id"
|
||||
DISCORD_BOT_TOKEN="op://Environment Variables - Naomi/Library/discord bot token"
|
||||
LIBRARY_ROLE_ID="op://Environment Variables - Naomi/Library/library role id"
|
||||
|
||||
# Application URL
|
||||
BASE_URL="op://Environment Variables - Naomi/Library/localhost url"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@library/source",
|
||||
"version": "1.1.0",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"dev": "nx run-many --target=build --all && NODE_ENV=production op run --env-file=dev.env -- node dist/api/main.js",
|
||||
|
||||
@@ -16,8 +16,6 @@ DISCORD_GUILD_ID="op://Environment Variables - Naomi/Library/discord server id"
|
||||
SPONSOR_ROLE_ID="op://Environment Variables - Naomi/Library/sponsor role id"
|
||||
MOD_ROLE_ID="op://Environment Variables - Naomi/Library/mod role id"
|
||||
STAFF_ROLE_ID="op://Environment Variables - Naomi/Library/staff role id"
|
||||
DISCORD_BOT_TOKEN="op://Environment Variables - Naomi/Library/discord bot token"
|
||||
LIBRARY_ROLE_ID="op://Environment Variables - Naomi/Library/library role id"
|
||||
|
||||
# Application URL
|
||||
BASE_URL="op://Environment Variables - Naomi/Library/base url"
|
||||
|
||||
Reference in New Issue
Block a user