【发布时间】:2020-09-30 14:31:13
【问题描述】:
我正在了解 Deno 的问题,但我在使用 Deno writeCSV() 实用程序写入 CSV 文件时遇到权限问题。我已经搭建了项目以在顶级 Docker 上运行
Dockerfile
CMD ["run", "--allow-read", "--allow-run", "--allow-write", "--allow-net", "main.ts"]
Main.ts
import { serve, readCSV, writeCSV } from "./deps.ts";
const URL = "https://www.getcats.com/api"
const DEFAULT_PRODUCT_ID = "xxxxxxxxxxxx";
const DEFAULT_DESCRIPTION = "Description";
const options = {
method: "POST",
url: URL,
body: {},
headers: {
"x-api-key": "xxxxxxxxxxxxx"
},
json: true // Automatically stringifies the body to JSON
};
// CSV File Properties
const f = await Deno.open("./inbound/example.csv");
const outputFile = await Deno.open("./outbound/outbound.csv", { write: true, create: true, read: true, truncate: true });
for await (const row of readCSV(f)) {
for await (const cell of row) {
queueMicrotask(async () => {
const response = await fetch(URL, {
method: "POST",
headers: {
'content-type': 'application/json',
"x-api-key": "xxxxxxxxxxxxxxx"
},
body: JSON.stringify({
memberId: cell,
productId: DEFAULT_PRODUCT_ID,
description: DEFAULT_DESCRIPTION
}),
});
response.json()
.then(async (res)=> {
const data = res.data;
const memberId = data.memberId;
const hashId = data.id;
const rows = [memberId, hashId]
console.log(`CAT ID: ${memberId} - HASH ID: ${hashId}`);
await writeCSV(outputFile, rows);
outputFile.close();
})
})
}
}
f.close();
我假设在运行容器时发送 ---allow-write 可以解决这个烫发问题。还有其他人在通过 Docker 写入 Deno 中的目录时遇到问题吗?
【问题讨论】:
-
如果你使用 -A 开关代替所有这些会发生什么?
-
你使用的是什么版本的 Deno?
-
- 运行:deno 1.0.0, v8 8.4.300 , typescript 3.9.2 - 我确实尝试使用 -A 命令运行它,但没有成功
-
@victorpalma 显示你的
deps.ts文件,我需要查看依赖项。 -
它只是从 Deno 库中导出:export { serve } from "deno.land/std@0.50.0/http/server.ts";从“deno.land/x/csv/mod.ts”导出 { readCSV, writeCSV };