Skip to content

Commit

Permalink
handle expired; pull bvid is force now
Browse files Browse the repository at this point in the history
  • Loading branch information
kingwingfly committed Feb 19, 2024
1 parent d3fd240 commit 2dd01c8
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
-->

## [Unreleased]
## [0.2.1] - 2024-02-20
- Handle Expired.
- Pull: If `pull bvid`, `fav` will force to pull it, as long as it's tracked and not expired.

## [0.2.0] - 2024-02-20
- Broken upgrade: the new `fav` is not compatible with the old `fav`. You need to delete `.fav` dir and re-`init` your `fav` after upgrading to `0.2.0`.
- Refactor: `fav` is completely rewritten in rusty style, and is now more generic and more maintainable.
- Simplify: Only `fetch` `pull` `status` `track` `init` `auth` `daemon` `completion` commands are supported now. The `modify` command is removed, since it's too tedious to modify status through a CLI tool.
- Status: Now `status` only show id, title and few status.
- Status: Now `status` only show id, title and few status.What's more, use --sets instead of --list, --res instead of --video
- Track: Now `track` does not support resource not in remote favorite sets. (In other words, there's no data only in local, but not in remote.)
- Pull: Now `pull` will call `fetch` first, and resources not tracked and fetched will never able to be pulled.
- Init: Only support bilibili now, so no args needed after `init`.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ documentation = ""
[workspace.dependencies]
fav_core = { path = "fav_core", version = "0.0.1-beta2" }
fav_derive = { path = "fav_derive", version = "0.0.1-beta1" }
fav_utils = { path = "fav_utils", version = "0.0.1-beta1" }
fav_utils = { path = "fav_utils", version = "0.0.1-beta2" }
fav_cli = { path = "fav_cli" }
fav_utils_old = { path = "fav_utils_old" }

Expand Down
2 changes: 1 addition & 1 deletion fav_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fav_cli"
version = "0.0.1-alpha1"
version = "0.0.1-alpha2"
authors.workspace = true
description = "Fav's CLI, helping persist the remote source. Repo: https://github.com/kingwingfly/fav"
license.workspace = true
Expand Down
26 changes: 17 additions & 9 deletions fav_cli/src/bili/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn status(id: String) -> FavCoreResult<()> {
} else if let Some(r) = try_find_res(&mut sets, &id_) {
r.table();
} else {
return Err(FavCoreError::IdNotFound(id));
return Err(FavCoreError::IdNotUsable(id));
}
Ok(())
}
Expand All @@ -59,7 +59,11 @@ pub(super) async fn fetch() -> FavCoreResult<()> {
let mut sub = sets.subset(|s| s.check_status(StatusFlags::TRACK));
bili.batch_fetch_set(&mut sub).await?;
for set in sub.iter_mut() {
let mut sub = set.subset(|r| r.check_status(StatusFlags::TRACK));
let mut sub = set.subset(|r| {
r.check_status(StatusFlags::TRACK)
& !r.check_status(StatusFlags::FETCHED)
& !r.check_status(StatusFlags::EXPIRED)
});
bili.batch_fetch_res(&mut sub).await?;
}
sets.write()
Expand All @@ -74,7 +78,7 @@ pub(super) fn track(id: String) -> FavCoreResult<()> {
} else if let Some(r) = try_find_res(&mut sets, &id_) {
r.on_status(StatusFlags::TRACK);
} else {
return Err(FavCoreError::IdNotFound(id));
return Err(FavCoreError::IdNotUsable(id));
}
sets.write()
}
Expand All @@ -88,7 +92,7 @@ pub(super) fn untrack(id: String) -> FavCoreResult<()> {
} else if let Some(r) = try_find_res(&mut sets, &id_) {
r.off_status(StatusFlags::TRACK);
} else {
return Err(FavCoreError::IdNotFound(id));
return Err(FavCoreError::IdNotUsable(id));
}
sets.write()
}
Expand All @@ -101,6 +105,7 @@ pub(super) async fn pull_all() -> FavCoreResult<()> {
for set in sub.iter_mut() {
let mut sub = set.subset(|r| {
!r.check_status(StatusFlags::SAVED)
& !r.check_status(StatusFlags::EXPIRED)
& r.check_status(StatusFlags::TRACK | StatusFlags::FETCHED)
});
bili.batch_pull_res(&mut sub).await?;
Expand All @@ -114,17 +119,20 @@ pub(super) async fn pull(id: String) -> FavCoreResult<()> {
let mut sets = BiliSets::read()?;
let id_ = Id::from(&id);
if let Some(s) = try_find_set(&mut sets, &id_) {
let mut sub =
s.subset(|r| !r.check_status(StatusFlags::SAVED) & r.check_status(StatusFlags::TRACK));
let mut sub = s.subset(|r| {
!r.check_status(StatusFlags::SAVED)
& !r.check_status(StatusFlags::EXPIRED)
& r.check_status(StatusFlags::TRACK | StatusFlags::FETCHED)
});
bili.batch_pull_res(&mut sub).await?;
} else if let Some(r) = try_find_res(&mut sets, &id_) {
if !r.check_status(StatusFlags::SAVED)
if !r.check_status(StatusFlags::EXPIRED)
& r.check_status(StatusFlags::TRACK | StatusFlags::FETCHED)
{
bili.pull_res(r).await?;
}
} else {
return Err(FavCoreError::IdNotFound(id));
return Err(FavCoreError::IdNotUsable(id));
}
sets.write()
}
Expand All @@ -140,7 +148,7 @@ pub(crate) async fn daemon(interval: u64) {
.format("%Y-%m-%d %H:%M:%S")
.to_string();
info!(
"Next job will be {} minutes later at {}.",
"Next job will be {} minutes later at {}.\n",
interval, next_ts_local
);
tokio::select! {
Expand Down
12 changes: 8 additions & 4 deletions fav_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub enum FavCoreError {
ProtobufError(protobuf::Error),
/// IO error
IoError(std::io::Error),
/// Id not found
IdNotFound(String),
/// Id not usable
IdNotUsable(String),
}

impl std::fmt::Display for FavCoreError {
Expand All @@ -44,8 +44,12 @@ impl std::fmt::Display for FavCoreError {
FavCoreError::IoError(source) => {
write!(f, "IOErr: {}; Maybe you didn't run `fav init`", source)
}
FavCoreError::IdNotFound(source) => {
write!(f, "Id<{}> not found", source)
FavCoreError::IdNotUsable(source) => {
write!(
f,
"Id<{}> not usable; Or maybe the resource is expired",
source
)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fav_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fav_utils"
version = "0.0.1-beta1"
version = "0.0.1-beta2"
authors.workspace = true
description = "Fav's utils crate; A collection of utilities and data structures for the fav project"
license.workspace = true
Expand Down
5 changes: 4 additions & 1 deletion fav_utils/src/bili/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ impl ResOps for Bili {
let params = vec![resource.bvid.clone()];
tokio::select! {
res = self.request_proto::<BiliRes>(ApiKind::FetchRes, params, "/data") => {
*resource |= res?;
match res {
Ok(res) => *resource |= res,
Err(_) => resource.on_status(StatusFlags::EXPIRED),
}
resource.on_status(StatusFlags::FETCHED);
},
_ = tokio::signal::ctrl_c() => {
Expand Down

0 comments on commit 2dd01c8

Please sign in to comment.