Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Backup / Export Filters #89

Open
sammcj opened this issue Nov 14, 2022 · 8 comments
Open

Feature: Backup / Export Filters #89

sammcj opened this issue Nov 14, 2022 · 8 comments

Comments

@sammcj
Copy link

sammcj commented Nov 14, 2022

It would be awesome if this tool could backup / export your Filters, currently I don't think there is a way to do this.

@kensanata
Copy link
Owner

Yeah, a bit like archiving accounts? I'm not quite convinced that I'd ever want to look at them… but who knows.

@sammcj
Copy link
Author

sammcj commented Nov 16, 2022

Sort of - but the use case I was thinking of was if you wanted to manage filters across multiple accounts.

Personally I have a huge list of filters and if for whatever reason the instance I am currently on went away I'd have to craft them all again.

Last night I had a crack at exporting them using a JS/TS library called Megalodon which made it surprisingly easy to export filters to JSON

async function filters() {
  const filters = await client.getFilters();
  return filters.data;
}

function backupFilters() {
  filters().then((filterObj) => {
    const json = JSON.stringify(filterObj, null, 2);
    fs.writeFileSync(`${outdir}/filters.json`, json);
  });
}

@kensanata
Copy link
Owner

It sounds like this wouldn't be all that useful unless there was also a way to upload those filters to a different account…

@sammcj
Copy link
Author

sammcj commented Nov 19, 2022

You can!

Here's an example I whipped up using that same JS/TS library:

async function uploadFilters(json: string) {
  const filterObj = JSON.parse(json);

  filterObj.forEach((filter: Entity.Filter) => {
    client.createFilter(filter.phrase, filter.context);
  });
}

Src: https://github.com/sammcj/mastapi/blob/main/src/upload.ts

@kensanata
Copy link
Owner

Interesting. If somebody adds it to mastodon-archive, I guess that would make sense. It'll need more command line arguments and all that, for sure.

@roycewilliams
Copy link

roycewilliams commented Feb 6, 2023

Strong second for exporting filters. I also have a huge number of filters. I've invested many hours in creating and improving them. Not only do I want them to be portable to other instances, I also want to back the filters up for BC/DR purposes (in case that instance is somehow lost, the instance accidentally deletes my filters, etc.).

@kensanata
Copy link
Owner

If somebody writes it, I'll add it.

@lapineige
Copy link

For reference to anyone willing to try to implement it, here is the related API : https://docs.joinmastodon.org/methods/filters/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants