Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

*Inspired by the larger sites that are now charging for core functionality, Scholarsome intends to be a drop-in replacement for any study workflow.*

https://scholarsome.com

<a href="https://discord.gg/hRgVvc5MKf">![](https://img.shields.io/badge/-Join%20our%20Discord-white?logo=Discord&logoColor=blue)</a>
<a href="https://github.com/hwgilbert16/scholarsome/blob/develop/LICENSE">![](https://img.shields.io/github/license/hwgilbert16/scholarsome?color=blue)</a>
<a href="https://github.com/hwgilbert16/scholarsome/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22">![](https://img.shields.io/badge/contributions-welcome-orange)</a>
Expand Down Expand Up @@ -61,13 +59,11 @@ You can read more about our design philosophy <a href="https://github.com/hwgilb

## Usage

Scholarsome is accessible at https://scholarsome.com for individuals who are not interested in hosting it themselves. It is free and runs the same as the most recently released version.

However, the service can be hosted yourself on any system. For those wishing to self-host Scholarsome, documentation for installation can be found <a href="https://scholarsome.com/handbook/installation/prerequisites">here.</a>
Scholarsome can be hosted yourself on any system. For those wishing to self-host Scholarsome, documentation for installation can be found <a href="https://github.com/hwgilbert16/scholarsome/blob/develop/apps/docs/docs/installation/installing.md">here.</a>

## Development

For development purposes, Scholarsome is required to be installed outside the standard container-based system that is used for production installs. Documentation for development can be found <a href="https://scholarsome.com/handbook/development/development-guide">here.</a>
For development purposes, Scholarsome is required to be installed outside the standard container-based system that is used for production installs. Documentation for development can be found <a href="https://github.com/hwgilbert16/scholarsome/blob/develop/apps/docs/docs/development/development-guide.md">here.</a>

While we use many technologies, some of our most prominent are:

Expand Down
27 changes: 24 additions & 3 deletions apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { TokenRefreshMiddleware } from "./providers/token-refresh.middleware";
import { ConvertingModule } from "./converting/converting.module";
import { StorageModule } from "./providers/storage/storage.module";
import { FoldersModule } from "./folders/folders.module";
import { ScheduleModule } from "@nestjs/schedule";
import { TasksService } from "./providers/tasks.service";

@Module({
imports: [
Expand All @@ -30,7 +32,7 @@ import { FoldersModule } from "./folders/folders.module";
cacheControl: true,
maxAge: 31536000
},
exclude: ["/api/(.*)", "/handbook/(.*)"]
exclude: ["/api/(.*)", "/handbook/(.*)", "/sitemaps/(.*)", "/sitemap.xml"]
}),
ServeStaticModule.forRoot({
rootPath: join(__dirname, "..", "docs"),
Expand All @@ -40,13 +42,31 @@ import { FoldersModule } from "./folders/folders.module";
maxAge: 31536000
}
}),
ServeStaticModule.forRoot({
rootPath: join(__dirname, "..", "..", "sitemaps"),
serveRoot: "/sitemaps",
serveStaticOptions: {
index: false,
cacheControl: true,
maxAge: 0
}
}),
ServeStaticModule.forRoot({
rootPath: join(__dirname, "..", "..", "sitemaps", "sitemap.xml"),
serveRoot: "/sitemap.xml",
serveStaticOptions: {
index: false,
cacheControl: true,
maxAge: 0
}
}),
ConfigModule.forRoot({
isGlobal: true
}),
RedisModule.forRootAsync({
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
defaultOptions: {
commonOptions: {
host: configService.get<string>("REDIS_HOST"),
port: configService.get<number>("REDIS_PORT"),
username: configService.get<string>("REDIS_USERNAME"),
Expand All @@ -64,6 +84,7 @@ import { FoldersModule } from "./folders/folders.module";
]
})
}),
ScheduleModule.forRoot(),
AuthModule,
DatabaseModule,
SetsModule,
Expand All @@ -86,7 +107,7 @@ import { FoldersModule } from "./folders/folders.module";
FoldersModule
],
controllers: [],
providers: [],
providers: [TasksService],
exports: [JwtModule]
})
export class AppModule implements NestModule {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/cards/cards.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class CardsService {
await this.storageService.getInstance()
.putFile("media/sets/" + fileName, decoded);

side = side.replace(source, "/api/sets/" + setId + "/media/" + fileName);
side = side.replace(source, "/api/sets/" + setId + "/media/" + name);
}
} else return false;

Expand Down
47 changes: 24 additions & 23 deletions apps/api/src/app/cards/dto/createCard.dto.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,59 @@
import { IsNotEmpty, IsNumber, IsOptional, IsString, IsUUID, Max, MaxLength, Min } from "class-validator";
import {
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
IsUUID,
Max,
Min,
} from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
import { Transform, TransformFnParams } from "class-transformer";
import * as sanitizeHtml from "sanitize-html";
import { sanitizationConfig } from "../../shared/sanitization/sanitization-config";

export class CreateCardDto {
@ApiProperty({
description: "The ID of the set that the card will belong to",
example: "27758237-5f57-4f6c-b483-6161056dad76",
minLength: 36,
maxLength: 36
maxLength: 36,
})
@IsUUID("4")
@IsNotEmpty()
setId: string;
setId: string;

@ApiProperty({
description: "The index of the card in the set",
example: 0,
minimum: 0,
maximum: 2147483647
maximum: 2147483647,
})
@IsNumber()
@Min(0)
@Max(2147483647)
@IsOptional()
index: number;
index: number;

@ApiProperty({
description: "The front or \"term\" of the card",
description: 'The front or "term" of the card',
example: "The definition of the card",
maxLength: 65535
})
@IsString()
@IsNotEmpty()
@MaxLength(65535)
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
term: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
term: string;

@ApiProperty({
description: "The back or \"definition\" of the card",
description: 'The back or "definition" of the card',
example: "The definition of the card",
maxLength: 65535
})
@IsString()
@IsNotEmpty()
@MaxLength(65535)
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
definition: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
definition: string;
}
46 changes: 23 additions & 23 deletions apps/api/src/app/cards/dto/updateCard.dto.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
import { IsNotEmpty, IsNumber, IsOptional, IsString, Max, MaxLength, Min } from "class-validator";
import {
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
Max,
Min,
} from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
import { Transform, TransformFnParams } from "class-transformer";
import * as sanitizeHtml from "sanitize-html";
import { sanitizationConfig } from "../../shared/sanitization/sanitization-config";

export class UpdateCardDto {
@ApiProperty({
description: "The index of the card in the set",
example: 0,
required: false,
minimum: 0,
maximum: 2147483647
maximum: 2147483647,
})
@IsNumber()
@IsOptional()
@Min(0)
@Max(2147483647)
@IsNotEmpty()
index?: number;
index?: number;

@ApiProperty({
description: "The front or \"term\" of the card",
description: 'The front or "term" of the card',
example: "The definition of the card",
maxLength: 65535,
required: false
required: false,
})
@IsString()
@IsOptional()
@IsNotEmpty()
@MaxLength(65535)
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
term?: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
term?: string;

@ApiProperty({
description: "The back or \"definition\" of the card",
description: 'The back or "definition" of the card',
example: "The definition of the card",
maxLength: 65535,
required: false
required: false,
})
@IsString()
@IsOptional()
@IsNotEmpty()
@MaxLength(65535)
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
definition?: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
definition?: string;
}
2 changes: 0 additions & 2 deletions apps/api/src/app/folders/folders.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ export class FoldersController {
@UseGuards(AuthenticatedGuard)
@Post()
async createFolder(@Body(HtmlDecodePipe) body: CreateFolderDto, @Request() req: ExpressRequest): Promise<ApiResponse<Folder>> {
console.log(body);

const user = await this.authService.getUserInfo(req);
if (!user) {
throw new UnauthorizedException({
Expand Down
18 changes: 18 additions & 0 deletions apps/api/src/app/folders/folders.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ export class FoldersService {
return folder.author.id === user.id;
}

/**
* Queries the database for every public folder's ID and when they were last modified
* Used for sitemap generation
*
* @returns Array of all folder IDs and when they were last updated
*/
async getSitemapFolderInfo(): Promise<{ id: string, updatedAt: Date }[]> {
return this.prisma.folder.findMany({
where: {
private: false
},
select: {
id: true,
updatedAt: true
}
});
}

/**
* Queries the database for a unique folder
*
Expand Down
Loading
Loading