| 210 | } |
| 211 | |
| 212 | export async function resolveActiveShareByToken(token: string): Promise<ResolvedShare | null> { |
| 213 | const [row] = await db |
| 214 | .select({ |
| 215 | share: publicShare, |
| 216 | file: workspaceFiles, |
| 217 | workspaceName: workspace.name, |
| 218 | ownerName: user.name, |
| 219 | }) |
| 220 | .from(publicShare) |
| 221 | .innerJoin(workspaceFiles, eq(workspaceFiles.id, publicShare.resourceId)) |
| 222 | .leftJoin(workspace, eq(workspace.id, workspaceFiles.workspaceId)) |
| 223 | .leftJoin(user, eq(user.id, workspaceFiles.userId)) |
| 224 | .where( |
| 225 | and( |
| 226 | eq(publicShare.token, token), |
| 227 | eq(publicShare.isActive, true), |
| 228 | eq(publicShare.resourceType, 'file'), |
| 229 | isNull(workspaceFiles.deletedAt) |
| 230 | ) |
| 231 | ) |
| 232 | .limit(1) |
| 233 | |
| 234 | if (!row) return null |
| 235 | |
| 236 | return { |
| 237 | share: row.share, |
| 238 | file: row.file, |
| 239 | workspaceName: row.workspaceName, |
| 240 | ownerName: row.ownerName, |
| 241 | } |
| 242 | } |