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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
node_modules
dist
*.db
*.tsbuildinfo
.env
uploads
.DS_Store
config.json
release
**/cache/*
**/cache/*
4 changes: 2 additions & 2 deletions backend/src/items/item.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export enum ItemStatus {
export const ItemTypeLabels = {
[ItemType.EXTENSION]: '扩展',
[ItemType.THEME]: '主题',
[ItemType.APP_EXTENSION]: 'APP扩展',
[ItemType.APP_THEME]: 'APP主题',
[ItemType.APP_EXTENSION]: '客户端扩展',
[ItemType.APP_THEME]: '客户端主题',
};

@Entity()
Expand Down
44 changes: 39 additions & 5 deletions backend/src/items/items.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ export class ItemsController {
return this.itemsService.getUserPurchases(req.user.userId, type);
}

@Get('url-rules')
@UseGuards(JwtAuthGuard)
async getUserUrlRules(@Request() req) {
return this.itemsService.getUserUrlRules(req.user.userId);
}

@Post('url-rules')
@UseGuards(JwtAuthGuard)
async setUserUrlRules(
@Body() body: { allowUrls?: string[]; blockUrls?: string[] },
@Request() req,
) {
return this.itemsService.setUserUrlRules(req.user.userId, body.allowUrls, body.blockUrls);
}

@Get('my-published')
@UseGuards(JwtAuthGuard)
async getMyPublished(@Request() req, @Query('type') type?: ItemType) {
Expand Down Expand Up @@ -155,17 +170,19 @@ export class ItemsController {
return;
}

const origin = req.query.origin;

const items = await this.itemsService.getUserPurchases(user.id);
const [items, globalUrlRules] = await Promise.all([
this.itemsService.getUserPurchases(user.id),
this.itemsService.getUserUrlRules(user.id),
]);
const extensionIds = items.filter(p => p.type === 'extension' && p.isEnabled).map(i => i.id);
const themeIds = items.filter(p => p.type === 'theme' && p.isEnabled).map(i => i.id);
const extensionData = items.filter(p => p.isEnabled)
.filter(p => !origin || p.matchUrls.some((pattern: string) => new RegExp(pattern.replace(/\*/g, '.*')).test(origin)))
.map(i => ({
id: i.id,
name: i.name,
matchUrls: i.matchUrls,
allowUrls: i.allowUrls,
blockUrls: i.blockUrls,
identifier: i.identifier,
dependencies: i.dependencies?.map(d => d.id) || []
}));
Expand All @@ -174,7 +191,8 @@ export class ItemsController {
.replace(/`{{#Ids}}`/, extensionIds.join(', '))
.replace(/`{{#Themes}}`/, themeIds.join(', '))
.replace(/['"`]{{#UserId}}['"`]/, `'${user.id}'`)
.replace(/\[`{{#ExtensionData}}`\]/, JSON.stringify(extensionData))
.replace(/\[`{{#ExtensionData}}`\]/, () => JSON.stringify(extensionData))
.replace(/\[`{{#GlobalUrlRules}}`\]/, () => JSON.stringify(globalUrlRules))
);
}

Expand Down Expand Up @@ -338,6 +356,22 @@ export class ItemsController {
return this.itemsService.findOne(id, req.user.userId);
}

@Get(':id/url-rules')
@UseGuards(JwtAuthGuard)
async getItemUrlRules(@Param('id', ParseIntPipe) id: number, @Request() req) {
return this.itemsService.getItemUrlRules(id, req.user.userId);
}

@Post(':id/url-rules')
@UseGuards(JwtAuthGuard)
async setItemUrlRules(
@Param('id', ParseIntPipe) id: number,
@Body() body: { allowUrls?: string[]; blockUrls?: string[] },
@Request() req,
) {
return this.itemsService.setItemUrlRules(id, req.user.userId, body.allowUrls, body.blockUrls);
}

@Get(':id/versions')
@UseGuards(JwtAuthGuard)
async getVersions(@Param('id', ParseIntPipe) id: number, @Request() req) {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/items/items.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { Item } from './item.entity';
import { UserItemState } from './user-item-state.entity';
import { Comment } from './comment.entity';
import { GlobalStorage } from './global-storage.entity';
import { UserUrlRule } from './user-url-rule.entity';
import { ItemsService } from './items.service';
import { ItemsController } from './items.controller';
import { UsersModule } from '../users/users.module';

@Module({
imports: [
TypeOrmModule.forFeature([Item, UserItemState, Comment, GlobalStorage]),
TypeOrmModule.forFeature([Item, UserItemState, UserUrlRule, Comment, GlobalStorage]),
forwardRef(() => UsersModule),
],
providers: [ItemsService],
Expand Down
Loading