Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

starting to rate #43

Closed
wants to merge 2 commits into from
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
6 changes: 3 additions & 3 deletions backend/open_api/ece461-project-phase2-fall2024-updated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ paths:
required: true
- examples:
ExampleToken:
value: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
value: bearer eyJhbGciOiJIUzI1...
name: X-Authorization
description: ""
schema:
Expand All @@ -250,7 +250,7 @@ paths:
examples:
ExampleRequestWithContent:
value:
Content: UEsDBBQAAAAAAA9DQlMAAAAAAAAAAAAAAAALACAAZXhjZXB0aW9ucy9VVA0AB35PWGF+T1hhfk9YYXV4CwABBPcBAAAEFAAAAFBLAwQUAAgACACqMCJTAAAAAAAAAABNAQAAJAAgAGV4Y2VwdGlvbnMvQ29tbWNvdXJpZXJFeGNlcHRpb24uamF2YVVUDQAH4KEwYeGhMGHgoTBhdXgLAAEE9wEAAAQUAAAAdY7NCoMwDMfvfYoct0tfQAYDGbv7BrVmW9DaksQhDN99BSc65gKBwP/jl+R86+4IPgabN/g4MCFbHD0mpdhLYQyFFFl/PIyijpVuzqvYCiVlO5axwWKJdDHUsbVXVEXOTef5MmmoO/LgOycC5dp5WbCAo2LfCFRDrxRwFV7GQJ7E9HSKsMUCf/0w+2bSHuPwN3vMFPiMPkjsVoTTHmcyk3kDUEsHCOEX4+uiAAAAT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97/xsQ8SZZJIyE2QK9WSaO/IF2Ac/4fiMZB+MiO7AdQSwcIIu3xZlgBAAAZAwAAUEsBAhQDFAAAAAAAD0NCUwAAAAAAAAAAAAAAAAsAIAAAAAAAAAAAAO1BAAAAAGV4Y2VwdGlvbnMvVVQNAAd+T1hhfk9YYX5PWGF1eAsAAQT3AQAABBQAAABQSwECFAMUAAgACACqMCJT4Rfj66IAAABNAQAAJAAgAAAAAAAAAAAApIFJAAAAZXhjZXB0aW9ucy9Db21tY291cmllckV4Y2VwdGlvbi5qYXZhVVQNAAfgoTBh4aEwYeChMGF1eAsAAQT3AQAABBQAAABQSwECFAMUAAgACACqMCJTlfA84wYBAAB9AgAAKgAgAAAAAAAAAAAApIFdAQAAZXhjZXB0aW9ucy9Db21tY291cmllckV4Y2VwdGlvbk1hcHBlci5qYXZhVVQNAAfgoTBh4aEwYeChMGF1eAsAAQT3AQAABBQAAABQSwECFAMUAAgACAAPQ0JTIu3xZlgBAAAZAwAAJgAgAAAAAAAAAAAApIHbAgAAZXhjZXB0aW9ucy9HZW5lcmljRXhjZXB0aW9uTWFwcGVyLmphdmFVVA0AB35PWGF/T1hhfk9YYXV4CwABBPcBAAAEFAAAAFBLBQYAAAAABAAEALcBAACnBAAAAAA=
Content: UEsDBBQAAAAAAA9DQlMAAAAAAAAAAAAAAAALA...
JSProgram: |
if (process.argv.length === 7) {
console.log('Success')
Expand Down Expand Up @@ -303,7 +303,7 @@ paths:
Version: 1.0.0
ID: underscore
data:
Content: UEsDBBQAAAAAAA9DQlMAAAAAAAAAAAAAAAALACAAZXhjZXB0aW9ucy9VVA0AB35PWGF+T1hhfk9YYXV4CwABBPcBAAAEFAAAAFBLAwQUAAgACACqMCJTAAAAAAAAAABNAQAAJAAgAGV4Y2VwdGlvbnMvQ29tbWNvdXJpZXJFeGNlcHRpb24uamF2YVVUDQAH4KEwYeGhMGHgoTBhdXgLAAEE9wEAAAQUAAAAdY7NCoMwDMfvfYoct0tfQAYDGbv7BrVmW9D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yFM+ubnXhvnt7ptA3YNJBYUa6MVlwZ6Rx/hhxQqzNl7usayCAnx89St93+nn8zxv2Y/jbexoNz4nh2ai16eQBE76Td/ZkJNE42hFEnxKEeB61m9G+7k+B3PIdqkIvG8Ylk7EZ4XYvR6KGpGGpX0nHaoq3y0aQR6lEQqMR82IQoi1RSJzGTJD81bWfgFOq2YhTwE97/xsQ8SZZJIyE2QK9WSaO/IF2Ac/4fiMZB+MiO7AdQSwcIIu3xZlgBAAAZAwAAUEsBAhQDFAAAAAAAD0NCUwAAAAAAAAAAAAAAAAsAIAAAAAAAAAAAAO1BAAAAAGV4Y2VwdGlvbnMvVVQNAAd+T1hhfk9YYX5PWGF1eAsAAQT3AQAABBQAAABQSwECFAMUAAgACACqMCJT4Rfj66IAAABNAQAAJAAgAAAAAAAAAAAApIFJAAAAZXhjZXB0aW9ucy9Db21tY291cmllckV4Y2VwdGlvbi5qYXZhVVQNAAfgoTBh4aEwYeChMGF1eAsAAQT3AQAABBQAAABQSwECFAMUAAgACACqMCJTlfA84wYBAAB9AgAAKgAgAAAAAAAAAAAApIFdAQAAZXhjZXB0aW9ucy9Db21tY291cmllckV4Y2VwdGlvbk1hcHBlci5qYXZhVVQNAAfgoTBh4aEwYeChMGF1eAsAAQT3AQAABBQAAABQSwECFAMUAAgACAAPQ0JTIu3xZlgBAAAZAwAAJgAgAAAAAAAAAAAApIHbAgAAZXhjZXB0aW9ucy9HZW5lcmljRXhjZXB0aW9uTWFwcGVyLmphdmFVVA0AB35PWGF/T1hhfk9YYXV4CwABBPcBAAAEFAAAAFBLBQYAAAAABAAEALcBAACnBAAAAAA=
Content: UEsDBBQAA...
JSProgram: |
if (process.argv.length === 7) {
console.log('Success')
Expand Down
21 changes: 17 additions & 4 deletions backend/src/handlers/PackageCreate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ async function extractFilesFromZip(zipBuffer: Buffer) {
const readmeFile = contents.file("README.md");
const readmeContent = readmeFile ? await readmeFile.async("string") : null;


const gitConfigFile = contents.file(".git/config");
Tridentinus marked this conversation as resolved.
Show resolved Hide resolved
const gitConfigContent = gitConfigFile ? await gitConfigFile.async("string") : null;

let repoUrl: string | null = null;

if (gitConfigContent) {
const match = gitConfigContent.match(/url = (.+)/);
repoUrl = match ? match[1].trim() : null;
}

return {
packageJson: packageJsonContent,
readme: readmeContent,
repoUrl: repoUrl,
};
}

Expand Down Expand Up @@ -114,19 +126,18 @@ export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPr
let version: string | null = null;
let fileUrl: string | null = null;
let fileSizeInMB = 0;

let repoUrl: string | null = null;
if (requestBody.Content) {
const fileContent = Buffer.from(requestBody.Content, 'base64');
const { packageJson, readme } = await extractFilesFromZip(fileContent);

const { packageJson, readme, repoUrl } = await extractFilesFromZip(fileContent);
const { packageJson } = await extractFilesFromZip(fileContent);
if (!packageJson) {
return createErrorResponse(400, 'package.json not found in the uploaded zip file.');
}

const metadata = extractMetadataFromPackageJson(packageJson);
packageName = metadata.packageName;
version = metadata.version;

if (!packageName || !version) {
return createErrorResponse(400, 'Package name or version could not be determined.');
}
Expand All @@ -135,6 +146,7 @@ export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPr
fileUrl = await uploadToS3(fileContent, packageName, version);
} else if (requestBody.URL) {
fileUrl = requestBody.URL;
repoUrl = null;
// Logic to fetch packageName and version if needed from URL (e.g., cloning a repo)
}

Expand Down Expand Up @@ -165,6 +177,7 @@ export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPr
Name: packageName,
Version: version,
ID: packageId,
repoUrl: repoUrl,
},
data: {
Content: fileUrl,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/PackageCreate/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ export const createErrorResponse = (statusCode: number, message: string): APIGat
headers: { 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json' },
body: JSON.stringify({ message }),
};
};
};
Loading