Skip to content
Open
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
16 changes: 1 addition & 15 deletions server/api/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,7 @@ async function updateCollectionImageAsset(
}
}

const accessKeyId = process.env.AWS_COLLECTIONDATA_ACCESS_KEY;
const secretAccessKey = process.env.AWS_COLLECTIONDATA_SECRET_KEY;
const region = process.env.AWS_COLLECTIONDATA_REGION;

if (!accessKeyId || !secretAccessKey || !region) {
throw new Error("Missing S3 configuration for asset upload.");
}

const storageClient = new S3Client({
credentials: {
accessKeyId,
secretAccessKey,
},
region,
});
const storageClient = new S3Client({ region: process.env.AWS_REGION });

const uploadCommand = new PutObjectCommand({
Bucket: process.env.AWS_COLLECTIONDATA_BUCKET,
Expand Down
14 changes: 2 additions & 12 deletions server/api/kb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});

export const KB_FILES_S3_CLIENT_CONFIG: S3ClientConfig = {
credentials: {
accessKeyId: process.env.AWS_KBFILES_ACCESS_KEY ?? "",
secretAccessKey: process.env.AWS_KBFILES_SECRET_KEY ?? "",
},
region: process.env.AWS_KBFILES_REGION ?? "",
};

async function getKBPage(
req: z.infer<typeof GetKBPageValidator>,
res: Response
Expand Down Expand Up @@ -287,14 +279,13 @@ async function addKBImage(
const page = await KBPage.findOne({ uuid: pageID }).orFail();

if (
!KB_FILES_S3_CLIENT_CONFIG ||
!process.env.AWS_KBFILES_BUCKET ||
!process.env.AWS_KBFILES_DOMAIN
) {
throw new Error("Missing file storage config");
}

const storageClient = new S3Client(KB_FILES_S3_CLIENT_CONFIG);
const storageClient = new S3Client({ region: process.env.AWS_REGION });
const imageFile = req.file;

if (!imageFile) {
Expand Down Expand Up @@ -921,13 +912,12 @@ function _checkForDeletedImages(newBody: string, oldURLs?: string[]) {
async function _deleteKBImagesFromStorage(urls: string[]): Promise<boolean> {
try {
if (
!KB_FILES_S3_CLIENT_CONFIG ||
!process.env.AWS_KBFILES_BUCKET ||
!process.env.AWS_KBFILES_DOMAIN
) {
throw new Error("Missing file storage config");
}
const storageClient = new S3Client(KB_FILES_S3_CLIENT_CONFIG);
const storageClient = new S3Client({ region: process.env.AWS_REGION });
const promises = [];

for (const url of urls) {
Expand Down
8 changes: 1 addition & 7 deletions server/api/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,7 @@ async function updateBrandingImageAsset(req: Request, res: Response) {
}
}

const storageClient = new S3Client({
credentials: {
accessKeyId: process.env.AWS_ORGDATA_ACCESS_KEY ?? '',
secretAccessKey: process.env.AWS_ORGDATA_SECRET_KEY ?? '',
},
region: process.env.AWS_ORGDATA_REGION,
});
const storageClient = new S3Client({ region: process.env.AWS_REGION });
const uploadCommand = new PutObjectCommand({
Bucket: process.env.AWS_ORGDATA_BUCKET,
Key: fileKey,
Expand Down
10 changes: 4 additions & 6 deletions server/api/projectfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import multer from "multer";
import Project from "../models/project.js";
import Organization from "../models/organization.js";
import {
PROJECT_FILES_S3_CLIENT_CONFIG,
computeStructureAccessSettings,
downloadProjectFiles,
getFolderContents,
Expand Down Expand Up @@ -182,7 +181,7 @@ export async function addProjectFile(
}

// Add a file
const storageClient = new S3Client(PROJECT_FILES_S3_CLIENT_CONFIG);
const storageClient = new S3Client({ region: process.env.AWS_REGION });
const providedFiles = Array.isArray(req.files) && req.files.length > 0;
const filesToCreate: RawProjectFileInterface[] = [];

Expand Down Expand Up @@ -603,7 +602,7 @@ async function bulkDownloadProjectFiles(
throw new Error("retrieveerror");
}

const storageClient = new S3Client(PROJECT_FILES_S3_CLIENT_CONFIG);
const storageClient = new S3Client({ region: process.env.AWS_REGION });
const downloadCommands: any[] = [];

if (foundFiles.length === 0) {
Expand Down Expand Up @@ -918,14 +917,13 @@ async function updateProjectFile(
};
}

const storageClient = new S3Client(PROJECT_FILES_S3_CLIENT_CONFIG);
const storageClient = new S3Client({ region: process.env.AWS_REGION });

const isPhysicalFile =
file.storageType === "file" && !file.isURL && !file.url && !file.isVideo;
if (isPhysicalFile && processedName && processedName !== file.name) {
// rename file
const fileKey = `${projectID}/${fileID}`;
const storageClient = new S3Client(PROJECT_FILES_S3_CLIENT_CONFIG);
const s3File = await storageClient.send(
new GetObjectCommand({
Bucket: process.env.AWS_PROJECTFILES_BUCKET,
Expand Down Expand Up @@ -1288,7 +1286,7 @@ async function removeProjectFilesInternal(projectID: string, fileIDs: string[])
.filter((obj) => obj !== null);

if (filesToDelete.length > 0) {
const storageClient = new S3Client(PROJECT_FILES_S3_CLIENT_CONFIG);
const storageClient = new S3Client({ region: process.env.AWS_REGION });
const deleteRes = await storageClient.send(
new DeleteObjectsCommand({
Bucket: process.env.AWS_PROJECTFILES_BUCKET,
Expand Down
3 changes: 1 addition & 2 deletions server/api/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
checkIfBookLinkedToProject,
updateTeamWorkbenchPermissions,
validateDefaultFileLicense,
PROJECT_THUMBNAILS_S3_CLIENT_CONFIG,
} from '../util/projectutils.js';
import {
checkBookIDFormat,
Expand Down Expand Up @@ -694,7 +693,7 @@ async function uploadProjectThumbnail(req, res) {
ContentDisposition: `inline; filename="${thumbnailKey}"`,
ContentType: thumbnail.mimetype ?? "application/octet-stream",
};
const s3Client = new S3Client(PROJECT_THUMBNAILS_S3_CLIENT_CONFIG);
const s3Client = new S3Client({ region: process.env.AWS_REGION });
const uploadResult = await s3Client.send(
new PutObjectCommand(thumbnailParams)
);
Expand Down
11 changes: 1 addition & 10 deletions server/api/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ import SupportTicketService from "./services/support-ticket-service";
import Project, { ProjectInterface } from "../models/project";
import base62 from "base62-random";

export const SUPPORT_FILES_S3_CLIENT_CONFIG: S3ClientConfig = {
credentials: {
accessKeyId: process.env.AWS_SUPPORTFILES_ACCESS_KEY ?? "",
secretAccessKey: process.env.AWS_SUPPORTFILES_SECRET_KEY ?? "",
},
region: process.env.AWS_SUPPORTFILES_REGION ?? "",
};

async function getTicket(
req: ZodReqWithOptionalUser<z.infer<typeof GetTicketValidator>>,
res: Response,
Expand Down Expand Up @@ -1644,14 +1636,13 @@ async function _uploadTicketAttachments(
): Promise<SupportTicketAttachmentInterface[]> {
try {
if (
!SUPPORT_FILES_S3_CLIENT_CONFIG ||
!process.env.AWS_SUPPORTFILES_BUCKET ||
!process.env.AWS_SUPPORTFILES_DOMAIN
) {
throw new Error("Missing file storage config");
}

const storageClient = new S3Client(SUPPORT_FILES_S3_CLIENT_CONFIG);
const storageClient = new S3Client({ region: process.env.AWS_REGION });
const uploadCommands: PutObjectCommand[] = [];
const savedFiles: SupportTicketAttachmentInterface[] = [];

Expand Down
3 changes: 1 addition & 2 deletions server/migrations/BookAncillaryMaterialsToProjectFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { debug, debugError } from '../debug.js';
import Book from '../models/book.js';
import Project from '../models/project.js';
import { getLibraryAndPageFromBookID } from '../util/bookutils.js';
import { PROJECT_FILES_S3_CLIENT_CONFIG } from '../util/projectutils.js';

/**
* Transfer Book "Materials" to their related Project, renamed as "Files".
Expand All @@ -13,7 +12,7 @@ export async function runMigration() {
const migrationTitle = 'Book Ancillary Materials to Project Files';
try {
debug(`Running migration "${migrationTitle}"...`);
const storageClient = new S3Client(PROJECT_FILES_S3_CLIENT_CONFIG);
const storageClient = new S3Client({ region: process.env.AWS_REGION });
const libraries = new Set();
const pageIDs = new Set();
const booksWithMaterials = (await Book.aggregate([
Expand Down
8 changes: 1 addition & 7 deletions server/util/librariesclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ import { getLibraryNameKeys } from "../api/libraries";
class LibrariesSSMClient {
public apiUsername: string = "LibreBot";
public libTokenPairPath: string = "/libkeys/production";
public ssm: SSMClient = new SSMClient({
credentials: {
accessKeyId: process.env.AWS_SSM_ACCESS_KEY_ID || "unknown",
secretAccessKey: process.env.AWS_SSM_SECRET_KEY || "unknown",
},
region: process.env.AWS_SSM_REGION || "unknown",
});
public ssm: SSMClient = new SSMClient({ region: process.env.AWS_REGION });

public credentialsCache: Record<
string,
Expand Down
21 changes: 2 additions & 19 deletions server/util/projectutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,6 @@ Conductor also promotes collaboration and organization among everyone on your OE
You can find in-depth guides on using the Commons and the Conductor to curate your resource in the [Construction Guide](https://chem.libretexts.org/Courses/Remixer_University/Construction_Guide_for_LibreTexts_2e/05%3A_Conductor).
`;

export const PROJECT_FILES_S3_CLIENT_CONFIG: S3ClientConfig = {
credentials: {
accessKeyId: process.env.AWS_PROJECTFILES_ACCESS_KEY ?? "",
secretAccessKey: process.env.AWS_PROJECTFILES_SECRET_KEY ?? "",
},
region: process.env.AWS_PROJECTFILES_REGION,
};


export const PROJECT_THUMBNAILS_S3_CLIENT_CONFIG = {
credentials: {
accessKeyId: process.env.AWS_PROJECT_THUMBNAILS_ACCESS_KEY ?? "",
secretAccessKey: process.env.AWS_PROJECT_THUMBNAILS_SECRET_KEY ?? "",
},
region: process.env.AWS_PROJECT_THUMBNAILS_REGION ?? "",
};

export const isProjectFileInterfaceAccess = (
access: string
): access is ProjectFileInterfaceAccess => {
Expand Down Expand Up @@ -577,7 +560,7 @@ export async function getFolderContents(
export async function getProjectFileS3Metadata(projectID: string, fileID: string): Promise<HeadObjectCommandOutput | null> {
try {
// @ts-ignore
const s3 = new S3Client(PROJECT_FILES_S3_CLIENT_CONFIG);
const s3 = new S3Client({ region: process.env.AWS_REGION });
const fileKey = `${projectID}/${fileID}`;
const command = new HeadObjectCommand({
Bucket: process.env.AWS_PROJECTFILES_BUCKET ?? "",
Expand Down Expand Up @@ -1026,7 +1009,7 @@ export async function createZIPAndNotify(
): Promise<boolean> {
try {
// @ts-ignore
const storageClient = new S3Client(PROJECT_FILES_S3_CLIENT_CONFIG);
const storageClient = new S3Client({ region: process.env.AWS_REGION });

const downloadCommands: GetObjectCommand[] = [];
fileKeys.forEach(async (key) => {
Expand Down
Loading