Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
ipfs-images-components
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ipfs-images
ipfs-images-components
Commits
77ac847f
Commit
77ac847f
authored
Aug 27, 2018
by
Дмитрий Никулин
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not try to clean objects that are missing from IPFS
parent
827f2dc4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
cleaner.js
components/cleaner.js
+12
-7
ipfs.js
components/storage-backends/ipfs.js
+3
-0
No files found.
components/cleaner.js
View file @
77ac847f
...
@@ -85,13 +85,20 @@ class Cleaner {
...
@@ -85,13 +85,20 @@ class Cleaner {
run
()
{
run
()
{
let
timestamp
=
Date
.
now
()
-
this
.
expire
*
1000
;
let
timestamp
=
Date
.
now
()
-
this
.
expire
*
1000
;
let
date
=
new
Date
(
timestamp
).
toUTCString
();
let
date
=
new
Date
(
timestamp
).
toUTCString
();
const
ipfs
=
new
Ipfs
();
logging
.
info
(
`Performing cleanup of attachments uploaded earlier
logging
.
info
(
`Performing cleanup of attachments uploaded earlier
than '
${
date
}
'`
);
than '
${
date
}
'`
);
logging
.
info
(
`Loading list of local attachments (ipfs pin ls). Please be patient, this can take a lot of time`
);
return
ipfs
.
getLocalObjects
().
then
(
hashes
=>
{
const
hashSet
=
new
Set
(
hashes
);
logging
.
info
(
'Looking for outdated attachments...'
);
return
redis
.
zrangebyscoreAsync
(
this
.
index
,
[
return
redis
.
zrangebyscoreAsync
(
this
.
index
,
[
'-inf'
,
timestamp
,
'-inf'
,
timestamp
,
]).
then
((
list
)
=>
{
]).
then
(
list
=>
{
list
=
list
.
filter
(
hash
=>
hashSet
.
has
(
hash
));
if
(
list
.
length
<=
0
)
{
if
(
list
.
length
<=
0
)
{
logging
.
info
(
'Nothing to clean'
);
logging
.
info
(
'Nothing to clean'
);
return
Promise
.
resolve
(
list
.
length
);
return
Promise
.
resolve
(
list
.
length
);
...
@@ -99,17 +106,15 @@ class Cleaner {
...
@@ -99,17 +106,15 @@ class Cleaner {
logging
.
info
(
`Deleting
${
list
.
length
}
attachments`
);
logging
.
info
(
`Deleting
${
list
.
length
}
attachments`
);
let
ipfs
=
new
Ipfs
();
return
Promise
.
map
(
list
,
(
hash
)
=>
{
let
metadata
=
new
Metadata
();
return
this
.
delAttachment
(
hash
);
}).
then
(()
=>
{
return
Promise
.
mapSeries
(
list
,
(
hash
)
=>
this
.
delAttachment
(
hash
)
).
then
(()
=>
{
logging
.
info
(
`Successfully deleted
${
list
.
length
}
attachments`
);
logging
.
info
(
`Successfully deleted
${
list
.
length
}
attachments`
);
});
});
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
logging
.
error
(
error
);
logging
.
error
(
error
);
});
});
});
}
}
}
}
...
...
components/storage-backends/ipfs.js
View file @
77ac847f
...
@@ -68,6 +68,9 @@ class IpfsStorage {
...
@@ -68,6 +68,9 @@ class IpfsStorage {
});
});
}
}
getLocalObjects
()
{
return
this
.
ipfs
.
pin
.
ls
();
}
/**
/**
* Pins a file by hash.
* Pins a file by hash.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment