@ -6,6 +6,7 @@ import { z } from 'zod'
|
|||||||
import { isWriteTypebotForbidden } from '../helpers/isWriteTypebotForbidden'
|
import { isWriteTypebotForbidden } from '../helpers/isWriteTypebotForbidden'
|
||||||
import { archiveResults } from '@typebot.io/results/archiveResults'
|
import { archiveResults } from '@typebot.io/results/archiveResults'
|
||||||
import { removeObjectsFromTypebot } from '@typebot.io/lib/s3/removeObjectsRecursively'
|
import { removeObjectsFromTypebot } from '@typebot.io/lib/s3/removeObjectsRecursively'
|
||||||
|
import { env } from '@typebot.io/env'
|
||||||
|
|
||||||
export const deleteTypebot = authenticatedProcedure
|
export const deleteTypebot = authenticatedProcedure
|
||||||
.meta({
|
.meta({
|
||||||
@ -86,10 +87,11 @@ export const deleteTypebot = authenticatedProcedure
|
|||||||
where: { id: typebotId },
|
where: { id: typebotId },
|
||||||
data: { isArchived: true, publicId: null, customDomain: null },
|
data: { isArchived: true, publicId: null, customDomain: null },
|
||||||
})
|
})
|
||||||
await removeObjectsFromTypebot({
|
if (env.S3_BUCKET)
|
||||||
workspaceId: existingTypebot.workspace.id,
|
await removeObjectsFromTypebot({
|
||||||
typebotId,
|
workspaceId: existingTypebot.workspace.id,
|
||||||
})
|
typebotId,
|
||||||
|
})
|
||||||
return {
|
return {
|
||||||
message: 'success',
|
message: 'success',
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ export const deleteWorkspace = authenticatedProcedure
|
|||||||
where: { id: workspaceId },
|
where: { id: workspaceId },
|
||||||
})
|
})
|
||||||
|
|
||||||
await removeObjectsFromWorkspace(workspaceId)
|
if (env.S3_BUCKET) await removeObjectsFromWorkspace(workspaceId)
|
||||||
|
|
||||||
if (isNotEmpty(workspace.stripeId) && env.STRIPE_SECRET_KEY) {
|
if (isNotEmpty(workspace.stripeId) && env.STRIPE_SECRET_KEY) {
|
||||||
const stripe = new Stripe(env.STRIPE_SECRET_KEY, {
|
const stripe = new Stripe(env.STRIPE_SECRET_KEY, {
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
removeAllObjectsFromResult,
|
removeAllObjectsFromResult,
|
||||||
removeObjectsFromResult,
|
removeObjectsFromResult,
|
||||||
} from '@typebot.io/lib/s3/removeObjectsRecursively'
|
} from '@typebot.io/lib/s3/removeObjectsRecursively'
|
||||||
|
import { env } from '../env/env'
|
||||||
|
|
||||||
type ArchiveResultsProps = {
|
type ArchiveResultsProps = {
|
||||||
typebot: Pick<Typebot, 'groups' | 'workspaceId' | 'id'>
|
typebot: Pick<Typebot, 'groups' | 'workspaceId' | 'id'>
|
||||||
@ -99,7 +100,7 @@ export const archiveResults =
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
if (!isDeletingAllResults) {
|
if (!isDeletingAllResults && env.S3_BUCKET) {
|
||||||
await removeObjectsFromResult({
|
await removeObjectsFromResult({
|
||||||
workspaceId: typebot.workspaceId,
|
workspaceId: typebot.workspaceId,
|
||||||
resultIds: resultIds,
|
resultIds: resultIds,
|
||||||
@ -108,7 +109,7 @@ export const archiveResults =
|
|||||||
}
|
}
|
||||||
} while (currentTotalResults >= batchSize)
|
} while (currentTotalResults >= batchSize)
|
||||||
|
|
||||||
if (isDeletingAllResults) {
|
if (isDeletingAllResults && env.S3_BUCKET) {
|
||||||
await removeAllObjectsFromResult({
|
await removeAllObjectsFromResult({
|
||||||
workspaceId: typebot.workspaceId,
|
workspaceId: typebot.workspaceId,
|
||||||
typebotId: typebot.id,
|
typebotId: typebot.id,
|
||||||
|
Reference in New Issue
Block a user