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
4 changes: 4 additions & 0 deletions __tests__/e2e/ci-mac-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ s deploy --trigger -t s2.yaml
s deploy --async-invoke-config -t s2.yaml
s info -t s2.yaml
s remove -y -t s2.yaml

echo "test layer code support http"
s layer publish --layer-name test --code https://test-gwh.oss-cn-hangzhou.aliyuncs.com/test.zip --compatible-runtime custom.debian12
s layer remove --layer-name test -y
cd ..

echo " ********* test scaling config *********"
Expand Down
2 changes: 1 addition & 1 deletion publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Type: Component
Name: fc3
Provider:
- 阿里云
Version: 0.1.17
Version: 0.1.18
Description: 阿里云函数计算全生命周期管理
HomePage: https://github.com/devsapp/fc3
Organization: 阿里云函数计算(FC)
Expand Down
40 changes: 37 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,15 @@ export async function _downloadFromUrl(url: string): Promise<string> {
extract: false,
});

logger.debug(`Downloaded file to: ${downloadPath}`);
const downloadFilePath = downloadPath.endsWith('.zip') ? downloadPath : `${downloadPath}.zip`;
logger.debug(`Downloaded file to: ${downloadFilePath}`);

// 返回下载文件路径,由主流程决定是否需要压缩
return downloadPath;
const isDownloadedFileZip = await isZipFile(downloadFilePath);
if (!isDownloadedFileZip) {
throw new Error(`Downloaded file is not a valid zip file: ${downloadFilePath}`);
}

return downloadFilePath;
} catch (error) {
// 如果下载失败,清理临时目录
try {
Expand All @@ -356,3 +361,32 @@ export async function _downloadFromUrl(url: string): Promise<string> {
throw new Error(`Failed to download code from URL: ${error.message}`);
}
}

/**
* 判断文件是否为ZIP文件 - 通过魔数检查
*/
async function isZipFile(filePath: string): Promise<boolean> {
try {
if (!fs.existsSync(filePath)) {
return false;
}

// 检查文件头部的魔数(而非扩展名)
const buffer = Buffer.alloc(4);
const fd = fs.openSync(filePath, 'r');
fs.readSync(fd, buffer, 0, 4, 0);
fs.closeSync(fd);

// ZIP文件的魔数是 50 4B 03 04 (十六进制)
const isZipMagicNumber =
buffer[0] === 0x50 &&
buffer[1] === 0x4b &&
(buffer[2] === 0x03 || buffer[2] === 0x05 || buffer[2] === 0x07) &&
(buffer[3] === 0x04 || buffer[3] === 0x06 || buffer[3] === 0x08);

return isZipMagicNumber;
} catch (error) {
logger.debug(`Error checking if file is zip: ${error.message}`);
return false;
}
}
Loading