-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce 1MB limit even for upgraded workspaces (#1894)
* Tweak poke * Enforce 1MB even for upgraded workspaces * migration to enforce 1mb on upgraded workspaces * nit alert
- Loading branch information
Showing
6 changed files
with
93 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
front/migrations/20230929_enforce_1mb_even_for_upgraded_workspaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Op } from "sequelize"; | ||
|
||
import { planForWorkspace } from "@app/lib/auth"; | ||
import { Workspace } from "@app/lib/models"; | ||
|
||
const { LIVE = false } = process.env; | ||
|
||
async function main() { | ||
console.log("Fetching Upgraded Worspaces..."); | ||
const workspaces = await Workspace.findAll({ | ||
where: { | ||
upgradedAt: { | ||
[Op.not]: null, | ||
}, | ||
}, | ||
}); | ||
console.log( | ||
`Found ${workspaces.length} workspaces for which to add largeModels = true` | ||
); | ||
|
||
const chunkSize = 16; | ||
const chunks = []; | ||
for (let i = 0; i < workspaces.length; i += chunkSize) { | ||
chunks.push(workspaces.slice(i, i + chunkSize)); | ||
} | ||
|
||
for (let i = 0; i < chunks.length; i++) { | ||
console.log(`Processing chunk ${i}/${chunks.length}...`); | ||
const chunk = chunks[i]; | ||
await Promise.all( | ||
chunk.map((workspace: Workspace) => { | ||
return set1MBLimit(!!LIVE, workspace); | ||
}) | ||
); | ||
} | ||
} | ||
|
||
async function set1MBLimit(live: boolean, workspace: Workspace) { | ||
const plan = planForWorkspace(workspace); | ||
plan.limits.dataSources.documents.sizeMb = 1; | ||
if (live) { | ||
await workspace.update({ | ||
plan: JSON.stringify(plan), | ||
}); | ||
} else { | ||
console.log(`Would have mutated ${workspace.sId}`); | ||
} | ||
} | ||
|
||
main() | ||
.then(() => { | ||
console.log("done"); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,7 +270,7 @@ async function handler( | |
api_error: { | ||
type: "data_source_quota_error", | ||
message: | ||
"Data sources document upload size is limited to 1MB on our free plan. Contact [email protected] if you want to increase it.", | ||
"Data sources document upload size is limited to 1MB. Contact [email protected] if you want to increase it.", | ||
}, | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,7 +187,7 @@ async function handler( | |
api_error: { | ||
type: "data_source_quota_error", | ||
message: | ||
"Data sources document upload size is limited to 1MB on our free plan. Contact [email protected] if you want to increase it.", | ||
"Data sources document upload size is limited to 1MB. Contact [email protected] if you want to increase it.", | ||
}, | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,10 +116,27 @@ export default function DataSourceUpsert({ | |
} | ||
}, [dataSource.name, loadDocumentId, owner.sId]); | ||
|
||
const alertDataSourcesLimit = () => { | ||
window.alert( | ||
"DataSource document upload size is limited to " + | ||
`${owner.plan.limits.dataSources.documents.sizeMb}MB (of raw text)` + | ||
". Contact [email protected] if you want to increase this limit." | ||
); | ||
}; | ||
|
||
const handleFileLoadedText = (e: any) => { | ||
const content = e.target.result; | ||
setText(content); | ||
setUploading(false); | ||
|
||
// Enforce plan limits: DataSource documents size. | ||
if ( | ||
owner.plan.limits.dataSources.documents.sizeMb != -1 && | ||
text.length > 1024 * 1024 * owner.plan.limits.dataSources.documents.sizeMb | ||
) { | ||
alertDataSourcesLimit(); | ||
return; | ||
} | ||
setText(content); | ||
}; | ||
|
||
const handleFileLoadedPDF = async (e: any) => { | ||
|
@@ -133,21 +150,21 @@ export default function DataSourceUpsert({ | |
const strings = content.items.map((item: any) => item.str); | ||
text += strings.join(" ") + "\n"; | ||
} | ||
setText(text); | ||
|
||
setUploading(false); | ||
}; | ||
|
||
const handleFileUpload = async (file: File) => { | ||
// Enforce plan limits: DataSource documents size. | ||
if ( | ||
owner.plan.limits.dataSources.documents.sizeMb != -1 && | ||
file.size > 1024 * 1024 * owner.plan.limits.dataSources.documents.sizeMb | ||
text.length > 1024 * 1024 * owner.plan.limits.dataSources.documents.sizeMb | ||
) { | ||
window.alert( | ||
"DataSource document upload size is limited to 1MB on our free plan. Contact [email protected] if you want to increase this limit." | ||
); | ||
alertDataSourcesLimit(); | ||
return; | ||
} | ||
setText(text); | ||
}; | ||
|
||
const handleFileUpload = async (file: File) => { | ||
setUploading(true); | ||
if (file.type === "application/pdf") { | ||
const fileReader = new FileReader(); | ||
|