Skip to content

Commit

Permalink
Downloading status/user during searching (with address) (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
mczachurski authored Nov 6, 2024
1 parent 9fe93a5 commit f25c9c5
Show file tree
Hide file tree
Showing 76 changed files with 1,555 additions and 1,213 deletions.
16 changes: 16 additions & 0 deletions Sources/ActivityPubKit/Entities/NodeInfoLinksDto.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// https://mczachurski.dev
// Copyright © 2024 Marcin Czachurski and the repository contributors.
// Licensed under the Apache License 2.0.
//

public struct NodeInfoLinksDto {
public let links: [NodeInfoLinkDto]

public init(links: [NodeInfoLinkDto]) {
self.links = links
}
}

extension NodeInfoLinksDto: Codable { }
extension NodeInfoLinksDto: Sendable { }
4 changes: 3 additions & 1 deletion Sources/ActivityPubKit/Entities/NodeInfoMetadataDto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

public struct NodeInfoMetadataDto {
public let nodeName: String
public let nodeDescription: String

public init(nodeName: String) {
public init(nodeName: String, nodeDescription: String) {
self.nodeName = nodeName
self.nodeDescription = nodeDescription
}
}

Expand Down
11 changes: 7 additions & 4 deletions Sources/VernissageServer/Application+Configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ extension Application {
try self.register(collection: UserAliasesController())
try self.register(collection: HealthController())
try self.register(collection: ErrorItemsController())

// Profile controller shuld be the last one (it registers: https://example.com/@johndoe).
try self.register(collection: ProfileController())
}

private func registerMiddlewares() {
Expand Down Expand Up @@ -447,12 +450,12 @@ extension Application {
let password = try await self.services.settingsService.get(.emailPassword, on: self.db)
let secureMethod = try await self.services.settingsService.get(.emailSecureMethod, on: self.db)

self.services.emailsService.setServerSettings(on: self,
hostName: hostName,
self.services.emailsService.setServerSettings(hostName: hostName,
port: port,
userName: userName,
password: password,
secureMethod: secureMethod)
secureMethod: secureMethod,
on: self)
}

private func configureS3() {
Expand Down Expand Up @@ -503,7 +506,7 @@ extension Application {
private func configureJsonCoders() {
// Create a new JSON encoder/decoder that uses unix-timestamp dates
let encoder = JSONEncoder()
encoder.outputFormatting = .sortedKeys
encoder.outputFormatting = [.sortedKeys, .withoutEscapingSlashes]
encoder.dateEncodingStrategy = .customISO8601

let decoder = JSONDecoder()
Expand Down
58 changes: 29 additions & 29 deletions Sources/VernissageServer/Controllers/AccountController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ struct AccountController {
let usersService = request.application.services.usersService
let isMachineTrusted = self.isMachineTrusted(on: request)

let user = try await usersService.login(on: request,
userNameOrEmail: loginRequestDto.userNameOrEmail,
let user = try await usersService.login(userNameOrEmail: loginRequestDto.userNameOrEmail,
password: loginRequestDto.password,
isMachineTrusted: isMachineTrusted)
isMachineTrusted: isMachineTrusted,
on: request)

let tokensService = request.application.services.tokensService
let accessToken = try await tokensService.createAccessTokens(on: request, forUser: user, useCookies: loginRequestDto.useCookies)
let accessToken = try await tokensService.createAccessTokens(forUser: user, useCookies: loginRequestDto.useCookies, on: request)

return try await self.createAccessTokenResponse(on: request,
accessToken: accessToken,
Expand Down Expand Up @@ -235,13 +235,13 @@ struct AccountController {
try ChangeEmailDto.validate(content: request)

let usersService = request.application.services.usersService
try await usersService.validateEmail(on: request, email: changeEmailDto.email)
try await usersService.validateEmail(email: changeEmailDto.email, on: request)

// Change email in database.
try await usersService.changeEmail(
on: request,
userId: authorizationPayloadId,
email: changeEmailDto.email
email: changeEmailDto.email,
on: request
)

// Send email with email confirmation message.
Expand Down Expand Up @@ -291,9 +291,9 @@ struct AccountController {
throw ConfirmEmailError.invalidIdOrToken
}

try await usersService.confirmEmail(on: request,
userId: userId,
confirmationGuid: confirmEmailRequestDto.confirmationGuid)
try await usersService.confirmEmail(userId: userId,
confirmationGuid: confirmEmailRequestDto.confirmationGuid,
on: request)

return HTTPStatus.ok
}
Expand Down Expand Up @@ -346,9 +346,9 @@ struct AccountController {
}

let emailsService = request.application.services.emailsService
try await emailsService.dispatchConfirmAccountEmail(on: request,
user: user,
redirectBaseUrl: resendEmailConfirmationDto.redirectBaseUrl)
try await emailsService.dispatchConfirmAccountEmail(user: user,
redirectBaseUrl: resendEmailConfirmationDto.redirectBaseUrl,
on: request)

return HTTPStatus.ok
}
Expand Down Expand Up @@ -401,10 +401,10 @@ struct AccountController {
let usersService = request.application.services.usersService

try await usersService.changePassword(
on: request,
userId: authorizationPayloadId,
currentPassword: changePasswordRequestDto.currentPassword,
newPassword: changePasswordRequestDto.newPassword
newPassword: changePasswordRequestDto.newPassword,
on: request
)

return HTTPStatus.ok
Expand Down Expand Up @@ -451,11 +451,11 @@ struct AccountController {
let usersService = request.application.services.usersService
let emailsService = request.application.services.emailsService

let user = try await usersService.forgotPassword(on: request, email: forgotPasswordRequestDto.email)
let user = try await usersService.forgotPassword(email: forgotPasswordRequestDto.email, on: request)

try await emailsService.dispatchForgotPasswordEmail(on: request,
user: user,
redirectBaseUrl: forgotPasswordRequestDto.redirectBaseUrl)
try await emailsService.dispatchForgotPasswordEmail(user: user,
redirectBaseUrl: forgotPasswordRequestDto.redirectBaseUrl,
on: request)

return HTTPStatus.ok
}
Expand Down Expand Up @@ -505,9 +505,9 @@ struct AccountController {

let usersService = request.application.services.usersService
try await usersService.confirmForgotPassword(
on: request,
forgotPasswordGuid: confirmationDto.forgotPasswordGuid,
password: confirmationDto.password
password: confirmationDto.password,
on: request
)

return HTTPStatus.ok
Expand Down Expand Up @@ -565,14 +565,14 @@ struct AccountController {

let tokensService = request.application.services.tokensService

let refreshTokenFromDb = try await tokensService.validateRefreshToken(on: request, refreshToken: oldRefreshToken.refreshToken)
let user = try await tokensService.getUserByRefreshToken(on: request, refreshToken: refreshTokenFromDb.token)
let refreshTokenFromDb = try await tokensService.validateRefreshToken(refreshToken: oldRefreshToken.refreshToken, on: request)
let user = try await tokensService.getUserByRefreshToken(refreshToken: refreshTokenFromDb.token, on: request)

let accessToken = try await tokensService.updateAccessTokens(on: request,
forUser: user,
let accessToken = try await tokensService.updateAccessTokens(forUser: user,
refreshToken: refreshTokenFromDb,
regenerateRefreshToken: oldRefreshToken.regenerateRefreshToken,
useCookies: oldRefreshToken.useCookies)
useCookies: oldRefreshToken.useCookies,
on: request)

return try await self.createAccessTokenResponse(on: request, accessToken: accessToken)
}
Expand Down Expand Up @@ -610,7 +610,7 @@ struct AccountController {

let usersService = request.application.services.usersService
let userNameNormalized = userName.deletingPrefix("@").uppercased()
let userFromDb = try await usersService.get(on: request.db, userName: userNameNormalized)
let userFromDb = try await usersService.get(userName: userNameNormalized, on: request.db)

guard let user = userFromDb else {
throw EntityNotFoundError.userNotFound
Expand All @@ -622,7 +622,7 @@ struct AccountController {
}

let tokensService = request.application.services.tokensService
try await tokensService.revokeRefreshTokens(on: request, forUser: user)
try await tokensService.revokeRefreshTokens(forUser: user, on: request)

return HTTPStatus.ok
}
Expand Down Expand Up @@ -806,7 +806,7 @@ struct AccountController {

private func sendConfirmEmail(on request: Request, user: User, redirectBaseUrl: String) async throws {
let emailsService = request.application.services.emailsService
try await emailsService.dispatchConfirmAccountEmail(on: request, user: user, redirectBaseUrl: redirectBaseUrl)
try await emailsService.dispatchConfirmAccountEmail(user: user, redirectBaseUrl: redirectBaseUrl, on: request)
}

private func createAccessTokenResponse(on request: Request, accessToken: AccessTokens, trustMachine: Bool? = nil) async throws -> Response {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct ActivityPubActorController {
/// - Parameters:
/// - request: The Vapor request to the endpoint.
///
/// - Returns: List of countries.
/// - Returns: Main instance actor data.
@Sendable
func read(request: Request) async throws -> Response {
let usersService = request.application.services.usersService
Expand Down Expand Up @@ -144,7 +144,7 @@ struct ActivityPubActorController {

// Skip requests from domains blocked by the instance.
let activityPubService = request.application.services.activityPubService
if try await activityPubService.isDomainBlockedByInstance(on: request.application, activity: activityDto) {
if try await activityPubService.isDomainBlockedByInstance(activity: activityDto, on: request.executionContext) {
request.logger.info("Activity blocked by instance (type: \(activityDto.type), id: '\(activityDto.id)', activityPubProfile: \(activityDto.actor.actorIds().first ?? "")")
return HTTPStatus.ok
}
Expand Down Expand Up @@ -204,7 +204,7 @@ struct ActivityPubActorController {

// Skip requests from domains blocked by the instance.
let activityPubService = request.application.services.activityPubService
if try await activityPubService.isDomainBlockedByInstance(on: request.application, activity: activityDto) {
if try await activityPubService.isDomainBlockedByInstance(activity: activityDto, on: request.executionContext) {
request.logger.info("Activity blocked by instance (type: \(activityDto.type), id: '\(activityDto.id)', activityPubProfile: \(activityDto.actor.actorIds().first ?? "")")
return HTTPStatus.ok
}
Expand Down
Loading

0 comments on commit f25c9c5

Please sign in to comment.