Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const maxStorageAllowedNotSubscribed = process.env
.MAX_STORAGE_ALLOWED_NOT_SUBSCRIBED
? +process.env.MAX_STORAGE_ALLOWED_NOT_SUBSCRIBED
: 1073741824;
export const PRESIGNED_URL_VALIDITY_MINUTES = 5;
export const PRESIGNED_URL_VALIDITY_MINUTES = 60;
export const PRESIGNED_URL_LENGTH = 100;
export const MEDIA_ID_LENGTH = 40;
export const APIKEY_RESTRICTION_REFERRER = "referrer";
Expand Down
62 changes: 62 additions & 0 deletions apps/api/src/media/chunked-upload-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import mongoose from "mongoose";

export interface ChunkedUpload {
uploadId: string;
userId: mongoose.Types.ObjectId;
apikey: string;
fileName: string;
originalFileName: string;
mimeType: string;
totalSize: number;
totalChunks: number;
uploadedChunks: number[];
chunks: Array<{
chunkNumber: number;
size: number;
etag?: string;
filePath: string;
}>;
access: string;
caption: string;
group?: string;
signature?: string;
createdAt: Date;
expiresAt: Date;
}

const ChunkedUploadSchema = new mongoose.Schema<ChunkedUpload>({
uploadId: { type: String, required: true, unique: true },
userId: { type: mongoose.Schema.Types.ObjectId, required: true },
apikey: { type: String, required: true },
fileName: { type: String, required: true },
originalFileName: { type: String, required: true },
mimeType: { type: String, required: true },
totalSize: { type: Number, required: true },
totalChunks: { type: Number, required: true },
uploadedChunks: [{ type: Number }],
chunks: [
{
chunkNumber: { type: Number, required: true },
size: { type: Number, required: true },
etag: { type: String },
filePath: { type: String, required: true },
},
],
access: { type: String, required: true },
caption: { type: String, default: "" },
group: { type: String },
signature: { type: String },
createdAt: { type: Date, default: Date.now },
expiresAt: {
type: Date,
default: () => new Date(Date.now() + 24 * 60 * 60 * 1000),
}, // 24 hours
});

// Index for cleanup
ChunkedUploadSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
ChunkedUploadSchema.index({ userId: 1 });
ChunkedUploadSchema.index({ uploadId: 1 });

export default mongoose.models.ChunkedUpload ||
mongoose.model("ChunkedUpload", ChunkedUploadSchema);
Loading