Skip to content

Commit cc300b7

Browse files
authored
Merge pull request #205 from import-ai/fix/bug
fix(bug): bug fix
2 parents 8b45b90 + 4084b5e commit cc300b7

17 files changed

+380
-20
lines changed

example.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
OBB_PORT=8000
22

3+
OBB_BASE_URL="https://test.omnibox.pro"
4+
35
OBB_WIZARD_BASE_URL=http://wizard:8000
46
OBB_LOG_LEVELS=error,warn,log
57

src/app/app.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
2-
ClassSerializerInterceptor,
32
DynamicModule,
43
MiddlewareConsumer,
54
Module,
65
NestModule,
76
ValidationPipe,
87
} from '@nestjs/common';
8+
import { SerializerInterceptor } from 'omniboxd/interceptor/serializer.interceptor';
99
import { APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';
1010
import { TypeOrmModule } from '@nestjs/typeorm';
1111
import { TagModule } from 'omniboxd/tag/tag.module';
@@ -42,6 +42,7 @@ import { ApiKeys1754550165406 } from 'omniboxd/migrations/1754550165406-api-keys
4242
import { ResourceAttachments1755059371000 } from 'omniboxd/migrations/1755059371000-resource-attachments';
4343
import { AddTagIdsToResources1755248141570 } from 'omniboxd/migrations/1755248141570-add-tag-ids-to-resources';
4444
import { TelemetryModule } from 'omniboxd/telemetry';
45+
import { SeoModule } from 'omniboxd/seo/seo.module';
4546
import { CleanResourceNames1755396702021 } from 'omniboxd/migrations/1755396702021-clean-resource-names';
4647
import { UpdateAttachmentUrls1755499552000 } from 'omniboxd/migrations/1755499552000-update-attachment-urls';
4748
import { ScanResourceAttachments1755504936756 } from 'omniboxd/migrations/1755504936756-scan-resource-attachments';
@@ -79,7 +80,7 @@ export class AppModule implements NestModule {
7980
},
8081
{
8182
provide: APP_INTERCEPTOR,
82-
useClass: ClassSerializerInterceptor,
83+
useClass: SerializerInterceptor,
8384
},
8485
{
8586
provide: APP_INTERCEPTOR,
@@ -111,6 +112,7 @@ export class AppModule implements NestModule {
111112
AttachmentsModule,
112113
SharesModule,
113114
SharedResourcesModule,
115+
SeoModule,
114116
TraceModule,
115117
FeedbackModule,
116118
ApplicationsModule,

src/auth/auth.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('AuthModule (e2e)', () => {
6868
email: 'nonexistent@example.com',
6969
password: client.user.password,
7070
})
71-
.expect(HttpStatus.FORBIDDEN);
71+
.expect(HttpStatus.NOT_FOUND);
7272
});
7373

7474
it('should fail with invalid password', async () => {

src/auth/auth.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class AuthService {
4444
if (isEmail(email)) {
4545
const userUseEmail = await this.userService.findByEmail(email);
4646
if (!userUseEmail) {
47-
throw new ForbiddenException(
47+
throw new NotFoundException(
4848
'No account found for the provided email. Please register first.',
4949
);
5050
}
@@ -63,6 +63,7 @@ export class AuthService {
6363
id: user.id,
6464
access_token: this.jwtService.sign({
6565
sub: user.id,
66+
username: user.username,
6667
}),
6768
};
6869
}

src/auth/google/google.service.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ConfigService } from '@nestjs/config';
44
import { SocialService } from 'omniboxd/auth/social.service';
55
import { UserService } from 'omniboxd/user/user.service';
66
import { NamespacesService } from 'omniboxd/namespaces/namespaces.service';
7+
import { CreateUserBindingDto } from 'omniboxd/user/dto/create-user-binding.dto';
78
import {
89
BadRequestException,
910
Injectable,
@@ -174,6 +175,24 @@ export class GoogleService extends SocialService {
174175
stateInfo.userInfo = returnValue;
175176
return returnValue;
176177
}
178+
// The email has already been used https://wqjowq8l2hl.feishu.cn/record/T8zVrlZjReK0HeceZ7icyh8qnze
179+
const linkedAccount = await this.userService.findByEmail(userData.email);
180+
if (linkedAccount) {
181+
const existingUser = await this.userService.bindingExistUser({
182+
userId: linkedAccount.id,
183+
loginType: 'google',
184+
loginId: userData.sub,
185+
});
186+
const returnValue = {
187+
id: existingUser.id,
188+
access_token: this.jwtService.sign({
189+
sub: existingUser.id,
190+
}),
191+
};
192+
stateInfo.userInfo = returnValue;
193+
return returnValue;
194+
}
195+
177196
return await this.dataSource.transaction(async (manager) => {
178197
let nickname = userData.name;
179198
if (!nickname) {
@@ -192,8 +211,9 @@ export class GoogleService extends SocialService {
192211
username,
193212
loginType: 'google',
194213
loginId: userData.sub,
214+
email: userData.email,
195215
lang,
196-
},
216+
} as CreateUserBindingDto,
197217
manager,
198218
);
199219

src/auth/jwt.strategy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
2626
});
2727
}
2828

29-
validate(payload: { sub: string; email?: string }) {
29+
validate(payload: { sub: string; email?: string; username?: string }) {
3030
return {
3131
id: payload.sub,
3232
email: payload.email,
33+
username: payload.username,
3334
};
3435
}
3536
}

src/auth/wechat/wechat.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ConfigService } from '@nestjs/config';
44
import { UserService } from 'omniboxd/user/user.service';
55
import { SocialService } from 'omniboxd/auth/social.service';
66
import { NamespacesService } from 'omniboxd/namespaces/namespaces.service';
7+
import { CreateUserBindingDto } from 'omniboxd/user/dto/create-user-binding.dto';
78
import {
89
Logger,
910
Injectable,
@@ -184,7 +185,7 @@ export class WechatService extends SocialService {
184185
loginType: 'wechat',
185186
loginId: userData.unionid,
186187
lang,
187-
},
188+
} as CreateUserBindingDto,
188189
manager,
189190
);
190191
await this.namespaceService.createUserNamespace(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ClassSerializerInterceptor } from '@nestjs/common/serializer';
2+
3+
export class SerializerInterceptor extends ClassSerializerInterceptor {
4+
serialize(response, options) {
5+
if (this.isNativeExpressResponse(response)) {
6+
return response;
7+
}
8+
return super.serialize(response, options);
9+
}
10+
11+
private isNativeExpressResponse(response) {
12+
if (!response || typeof response !== 'object') {
13+
return false;
14+
}
15+
16+
if (response.constructor?.name === 'ServerResponse') {
17+
return true;
18+
}
19+
20+
return ['statusCode', 'send', 'getHeader', 'req'].every(
21+
(feat) => feat in response,
22+
);
23+
}
24+
}

src/interceptor/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function transformKeysToSnakeCase(data: any): any {
1515
return Object.keys(data).reduce((acc, key) => {
1616
const snakeKey = camelToSnake(key);
1717
acc[snakeKey] = transformKeysToSnakeCase(data[key]);
18+
1819
return acc;
1920
}, {});
2021
}

src/namespace-resources/namespace-resources.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { InjectRepository } from '@nestjs/typeorm';
22
import duplicateName from 'omniboxd/utils/duplicate-name';
3-
import {
4-
encodeFileName,
5-
getOriginalFileName,
6-
} from 'omniboxd/utils/encode-filename';
73
import {
84
DataSource,
95
EntityManager,
@@ -41,6 +37,10 @@ import { ResourceAttachmentsService } from 'omniboxd/resource-attachments/resour
4137
import { ResourcesService } from 'omniboxd/resources/resources.service';
4238
import { ResourceMetaDto } from 'omniboxd/resources/dto/resource-meta.dto';
4339
import { ChildrenMetaDto } from './dto/list-children-resp.dto';
40+
import {
41+
encodeFileName,
42+
getOriginalFileName,
43+
} from 'omniboxd/utils/encode-filename';
4444
import { isEmpty } from 'omniboxd/utils/is-empty';
4545

4646
const TASK_PRIORITY = 5;
@@ -653,6 +653,7 @@ export class NamespaceResourcesService {
653653
) {
654654
const originalName = getOriginalFileName(fileName);
655655
const encodedName = encodeFileName(fileName);
656+
656657
let resource: Resource;
657658
if (resourceId) {
658659
resource = await this.resourcesService.getResourceOrFail(

0 commit comments

Comments
 (0)