Skip to content

Commit

Permalink
store size
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikey committed Jul 9, 2021
1 parent cf0c6eb commit 1c9153d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ oid sha256:a480292a083cffbae4602079113e3b6ed8e7ed24ffabda282eb2054460ad7325
size 65898
```

Your files are now stored on Skynet. To continue working with your files locally, use `git lfs`!

```
git checkout branch
git lfs fetch
git lfs checkout
```

Your images are downloaded from Skynet, and the pointer files are updated locally.

## No Verification

Why? Because git lfs doesn't use it to prevent commit. If a server responds 200 to an upload, git lfs is hitting verification for the benefit of the server. When this changes, verification will be enabled.
Expand Down
8 changes: 5 additions & 3 deletions src/routes/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@ export default function (fastify: any) {
req.params.repo,
req.params.oid
);
if (size < 0) {
res.code(404).send();

if (size <= 0) {
return res.code(404).send();
}

const dataStream: any = await store.get(
req.params.user,
req.params.repo,
req.params.oid
);
res.headers("Content-Length", dataStream.fileData.length);

res.headers("Content-Length", dataStream.size);
res.type(dataStream.fileType.mime);
res.code(200).send(dataStream.fileData);
});
Expand Down
14 changes: 8 additions & 6 deletions src/store/siasky_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const fileSchema: any = new mongoose.Schema({
user: String,
repo: String,
skylink: String,
size: String,
});

const File = mongoose.model("File", fileSchema);
Expand Down Expand Up @@ -103,10 +104,11 @@ export default class SiaSkyStore extends Store {

async put(user: any, repo: any, oid: any, stream: any) {
var self: any = this;
const size = stream.headers["content-length"];
const skylink = await self._skynet.uploadFile(
Buffer.from(stream.body, "binary")
);
const file = new File({ user, repo, oid, skylink });
const file = new File({ user, repo, oid, skylink, size });
file.save(function (err) {
if (err) return console.error(err);
});
Expand All @@ -122,6 +124,7 @@ export default class SiaSkyStore extends Store {
return {
fileType,
fileData,
size: file[0].size,
};
}

Expand All @@ -131,14 +134,13 @@ export default class SiaSkyStore extends Store {
? {
oid: file[0].oid,
skylink: file[0].skylink.replace("sia://", "https://siasky.net/"),
size: file[0].size,
}
: {};
}

getSize(user: any, repo: any, oid: any) {
var self = this;
return new Promise(function (resolve, reject) {
resolve(1);
});
async getSize(user: any, repo: any, oid: any) {
const file: any = await File.find({ oid: `${oid}` });
return file[0] && file[0].size ? file[0].size : 0;
}
}

0 comments on commit 1c9153d

Please sign in to comment.