Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelFur committed Dec 28, 2022
2 parents e6b70d0 + a0984ef commit 26ed0e9
Show file tree
Hide file tree
Showing 193 changed files with 5,132 additions and 2,831 deletions.
4 changes: 4 additions & 0 deletions .yarn/versions/6db1bf03.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
undecided:
- root-workspace-0b6124
- picsur-backend
- picsur-frontend
4 changes: 2 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"
spec: '@yarnpkg/plugin-version'
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
spec: '@yarnpkg/plugin-workspace-tools'

yarnPath: .yarn/releases/yarn-berry.cjs
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ But it does function, so feel free to give it a try.

## Demo

You can view a live demo here: <https://picsur.rubikscraft.nl/>
You can view a live demo here: <https://picsur.org/>

The images are deleted every five minutes, and the maximum filesize is 16MB. But it should give you an indication of how it works.

Expand Down Expand Up @@ -57,9 +57,9 @@ Every featured marked here should work in the latest release.
- [x] Proper DB migrations
- [x] Show own images in list
- [x] Correct previews on chats
- [X] Expiring images
- [X] ShareX endpoint
- [X] Arm64 image
- [x] Expiring images
- [x] ShareX endpoint
- [x] ARM64 and AMD64 Docker image

- [ ] White mode
- [ ] Public gallery
Expand All @@ -74,6 +74,12 @@ If you like this project, don't forget to give it a star. It tells me that I'm n

## Faq

### Is this project maintained?

Yes it still is. If I were to stop maintaining it, I would archive the repository.

However I do not have a lot of time on my hands, so updates are not always as frequent as I would like them to be.

### Why do my images dissapear of the public instance?

The public instance is only a demo, and therefore only keeps images for 5 minutes. This is to prevent the server from running out of disk space, and to prevent people from using it to host questionable images.
Expand Down Expand Up @@ -150,6 +156,10 @@ volumes:
picsur-data:
```
## Thanks
- @awg13 for donating 5$
## Api
Here is a usually up to date documentation of the api:
Expand Down
56 changes: 30 additions & 26 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picsur-backend",
"version": "0.4.1",
"version": "0.5.0",
"description": "Backend for Picsur",
"license": "GPL-3.0",
"repository": "https://github.com/rubikscraft/Picsur",
Expand All @@ -22,65 +22,69 @@
"purge": "rm -rf dist && rm -rf node_modules"
},
"dependencies": {
"@fastify/helmet": "^10.0.1",
"@fastify/multipart": "^7.2.0",
"@fastify/static": "^6.5.0",
"@nestjs/common": "^9.1.4",
"@fastify/helmet": "^10.1.0",
"@fastify/multipart": "^7.3.0",
"@fastify/reply-from": "^8.3.1",
"@fastify/static": "^6.6.0",
"@nestjs/common": "^9.2.1",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.1.4",
"@nestjs/core": "^9.2.1",
"@nestjs/jwt": "^9.0.0",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-fastify": "^9.1.4",
"@nestjs/platform-fastify": "^9.2.1",
"@nestjs/schedule": "^2.1.0",
"@nestjs/serve-static": "^3.0.0",
"@nestjs/throttler": "^3.1.0",
"@nestjs/typeorm": "^9.0.1",
"bcrypt": "^5.1.0",
"bmp-img": "^1.2.1",
"cors": "^2.8.5",
"file-type": "^18.0.0",
"is-docker": "^3.0.0",
"ms": "^2.1.3",
"node-fetch": "^3.2.10",
"p-timeout": "^6.0.0",
"passport": "^0.6.0",
"passport-headerapikey": "^1.2.2",
"passport-jwt": "^4.0.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"passport-strategy": "^1.0.0",
"pg": "^8.8.0",
"picsur-shared": "*",
"posix.js": "^0.1.1",
"qoi-img": "^2.1.0",
"qoi-img": "^2.1.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.7",
"sharp": "^0.31.1",
"rxjs": "^7.8.0",
"sharp": "^0.31.3",
"stream-parser": "^0.3.1",
"thunks": "^4.9.6",
"typeorm": "0.3.10",
"zod": "^3.19.1"
"typeorm": "0.3.11",
"zod": "^3.20.2"
},
"devDependencies": {
"@nestjs/cli": "^9.1.4",
"@nestjs/cli": "^9.1.5",
"@nestjs/schematics": "^9.0.3",
"@nestjs/testing": "^9.1.4",
"@nestjs/testing": "^9.2.1",
"@types/bcrypt": "^5.0.0",
"@types/cors": "^2.8.12",
"@types/ms": "^0.7.31",
"@types/cors": "^2.8.13",
"@types/multer": "^1.4.7",
"@types/node": "^18.8.4",
"@types/passport-jwt": "^3.0.7",
"@types/node": "^18.11.17",
"@types/passport-jwt": "^3.0.8",
"@types/passport-local": "^1.0.34",
"@types/passport-strategy": "^0.2.35",
"@types/sharp": "^0.31.0",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"eslint": "^8.25.0",
"@typescript-eslint/eslint-plugin": "^5.47.0",
"@typescript-eslint/parser": "^5.47.0",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1",
"prettier": "^2.8.1",
"source-map-support": "^0.5.21",
"ts-loader": "^9.4.1",
"ts-loader": "^9.4.2",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"typescript": "4.8.4"
"tsconfig-paths": "^4.1.1",
"typescript": "^4.9.4"
}
}
6 changes: 6 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';
import { ServeStaticModule } from '@nestjs/serve-static';
import cors from 'cors';
import { IncomingMessage, ServerResponse } from 'http';
import { EarlyConfigModule } from './config/early/early-config.module';
import { ServeStaticConfigService } from './config/early/serve-static.config.service';
import { DatabaseModule } from './database/database.module';
import { PicsurLayersModule } from './layers/PicsurLayers.module';
import { PicsurLoggerModule } from './logger/logger.module';
import { AuthManagerModule } from './managers/auth/auth.module';
import { DemoManagerModule } from './managers/demo/demo.module';
import { UsageManagerModule } from './managers/usage/usage.module';
import { PicsurRoutesModule } from './routes/routes.module';

const mainCorsConfig = cors({
Expand Down Expand Up @@ -41,10 +44,13 @@ const imageCorsOverride = (
useExisting: ServeStaticConfigService,
imports: [EarlyConfigModule],
}),
ScheduleModule.forRoot(),
DatabaseModule,
AuthManagerModule,
UsageManagerModule,
DemoManagerModule,
PicsurRoutesModule,
PicsurLayersModule,
],
})
export class AppModule implements NestModule {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/collections/apikey-db/apikey-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FindResult } from 'picsur-shared/dist/types/find-result';
import { generateRandomString } from 'picsur-shared/dist/util/random';
import { Repository } from 'typeorm';
import { EApiKeyBackend } from '../../database/entities/apikey.entity';
import { EUserBackend } from '../../database/entities/user.entity';
import { EUserBackend } from '../../database/entities/users/user.entity';

@Injectable()
export class ApiKeyDbService {
Expand Down
6 changes: 3 additions & 3 deletions backend/src/collections/image-db/image-db.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { EImageDerivativeBackend } from '../../database/entities/image-derivative.entity';
import { EImageFileBackend } from '../../database/entities/image-file.entity';
import { EImageBackend } from '../../database/entities/image.entity';
import { EImageDerivativeBackend } from '../../database/entities/images/image-derivative.entity';
import { EImageFileBackend } from '../../database/entities/images/image-file.entity';
import { EImageBackend } from '../../database/entities/images/image.entity';
import { ImageDBService } from './image-db.service';
import { ImageFileDBService } from './image-file-db.service';

Expand Down
10 changes: 9 additions & 1 deletion backend/src/collections/image-db/image-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AsyncFailable, Fail, FT } from 'picsur-shared/dist/types';
import { FindResult } from 'picsur-shared/dist/types/find-result';
import { generateRandomString } from 'picsur-shared/dist/util/random';
import { In, LessThan, Repository } from 'typeorm';
import { EImageBackend } from '../../database/entities/image.entity';
import { EImageBackend } from '../../database/entities/images/image.entity';

@Injectable()
export class ImageDBService {
Expand Down Expand Up @@ -83,6 +83,14 @@ export class ImageDBService {
}
}

public async count(): AsyncFailable<number> {
try {
return await this.imageRepo.count();
} catch (e) {
return Fail(FT.Database, e);
}
}

public async update(
id: string,
userid: string | undefined,
Expand Down
42 changes: 38 additions & 4 deletions backend/src/collections/image-db/image-file-db.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { ImageEntryVariant } from 'picsur-shared/dist/dto/image-entry-variant.enum';
import { AsyncFailable, Fail, FT } from 'picsur-shared/dist/types';
import { AsyncFailable, Fail, FT, HasFailed } from 'picsur-shared/dist/types';
import { LessThan, Repository } from 'typeorm';
import { EImageDerivativeBackend } from '../../database/entities/image-derivative.entity';
import { EImageFileBackend } from '../../database/entities/image-file.entity';
import { EImageDerivativeBackend } from '../../database/entities/images/image-derivative.entity';
import { EImageFileBackend } from '../../database/entities/images/image-file.entity';

const A_DAY_IN_SECONDS = 24 * 60 * 60;

Expand Down Expand Up @@ -57,6 +57,40 @@ export class ImageFileDBService {
}
}

public async migrateFile(
imageId: string,
sourceVariant: ImageEntryVariant,
targetVariant: ImageEntryVariant,
): AsyncFailable<EImageFileBackend> {
try {
const sourceFile = await this.getFile(imageId, sourceVariant);
if (HasFailed(sourceFile)) return sourceFile;

sourceFile.variant = targetVariant;
return await this.imageFileRepo.save(sourceFile);
} catch (e) {
return Fail(FT.Database, e);
}
}

public async deleteFile(
imageId: string,
variant: ImageEntryVariant,
): AsyncFailable<EImageFileBackend> {
try {
const found = await this.imageFileRepo.findOne({
where: { image_id: imageId, variant: variant },
});

if (!found) return Fail(FT.NotFound, 'Image not found');

await this.imageFileRepo.delete({ image_id: imageId, variant: variant });
return found;
} catch (e) {
return Fail(FT.Database, e);
}
}

// This is useful because you dont have to pull the whole image file
public async getFileTypes(
imageId: string,
Expand Down Expand Up @@ -129,7 +163,7 @@ export class ImageFileDBService {
): AsyncFailable<number> {
try {
const result = await this.imageDerivativeRepo.delete({
last_read: LessThan(new Date()),
last_read: LessThan(new Date(Date.now() - olderThanSeconds * 1000)),
});

return result.affected ?? 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type EnumValue<E> = E[keyof E];
type PrefValueTypeType<E extends Enum> = {
[key in EnumValue<E>]: PrefValueTypeStrings;
};
type EncodedPref = {
key: string;
type EncodedPref<E extends Enum> = {
key: EnumValue<E>;
value: string;
};

Expand All @@ -32,7 +32,7 @@ export class PreferenceCommonService {
// E is either the SysPreference or the UsrPreference enum
// the pref value types is the object containing the type of each key in E
public DecodePref<E extends Enum>(
preference: EncodedPref,
preference: EncodedPref<E>,
prefType: E,
prefValueTypes: PrefValueTypeType<E>,
): Failable<DecodedPref> {
Expand Down Expand Up @@ -69,7 +69,7 @@ export class PreferenceCommonService {
value: PrefValueType,
prefType: E,
prefValueTypes: PrefValueTypeType<E>,
): AsyncFailable<EncodedPref> {
): AsyncFailable<EncodedPref<E>> {
const validatedKey = this.validatePrefKey(key, prefType);
if (HasFailed(validatedKey)) return validatedKey;

Expand Down
4 changes: 2 additions & 2 deletions backend/src/collections/preference-db/preference-db.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { EarlyConfigModule } from '../../config/early/early-config.module';
import { ESysPreferenceBackend } from '../../database/entities/sys-preference.entity';
import { EUsrPreferenceBackend } from '../../database/entities/usr-preference.entity';
import { ESysPreferenceBackend } from '../../database/entities/system/sys-preference.entity';
import { EUsrPreferenceBackend } from '../../database/entities/system/usr-preference.entity';
import { PreferenceCommonService } from './preference-common.service';
import { PreferenceDefaultsService } from './preference-defaults.service';
import { SysPreferenceDbService } from './sys-preference-db.service';
Expand Down
Loading

0 comments on commit 26ed0e9

Please sign in to comment.