feat(billing): cap each owner's stored file volume
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import axios from 'axios';
|
||||
import { computed, ref, shallowRef } from 'vue';
|
||||
import type { ConversationRoomDto, ConversationSessionDto } from '@mento/shared';
|
||||
import type { ConversationRoomDto, ConversationSessionDto, StorageUsageDto } from '@mento/shared';
|
||||
import { api } from '@/lib/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
|
||||
export type ChatDelivery = 'sending' | 'sent' | 'read';
|
||||
|
||||
@@ -1344,8 +1346,14 @@ export async function refreshUnreadTotal() {
|
||||
}
|
||||
|
||||
export function useOrgChat() {
|
||||
const auth = useAuthStore();
|
||||
const loadingMessages = ref(false);
|
||||
|
||||
function rememberStorage(usage: StorageUsageDto) {
|
||||
if (!auth.user) return;
|
||||
auth.setUser({ ...auth.user, storage: usage });
|
||||
}
|
||||
|
||||
async function ensureConnected() {
|
||||
await connectSocket();
|
||||
}
|
||||
@@ -1696,10 +1704,15 @@ export function useOrgChat() {
|
||||
}
|
||||
}
|
||||
setProgress(12);
|
||||
await api.post('/conversations/files/reserve', { bytes: fileForUpload.size });
|
||||
const uploadedPath = await uploadChatFile(session.uploadUrl, fileForUpload, (p) => {
|
||||
setProgress(12 + Math.round(p * 0.86));
|
||||
});
|
||||
setProgress(99);
|
||||
const committed = await api.post<StorageUsageDto>('/conversations/files/commit', {
|
||||
bytes: fileForUpload.size,
|
||||
});
|
||||
rememberStorage(committed.data);
|
||||
await sendMediaPath(roomId, uploadedPath, type, {
|
||||
reply,
|
||||
fileName: outboundFileName,
|
||||
@@ -1715,6 +1728,11 @@ export function useOrgChat() {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (axios.isAxiosError(e)) {
|
||||
const raw = (e.response?.data as { message?: string | string[] } | undefined)?.message;
|
||||
const text = Array.isArray(raw) ? raw.join(' ') : raw;
|
||||
if (text) throw new Error(text);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user