#Regex Filtering/Array Matching in Flow

14 messages · Page 1 of 1 (latest)

last tiger
#

Hey there,

I'm looking to design a system where a user submits data into the database, to then be approved by an admin. It isn't known what the user might enter exactly but it's highly likely they will enter a string that may contain a name that matches a table of names in the DB. Is there someway I can use Flows and possibly regex to match their entry to an item in the DB?

Here is what I have working in VS:

var artists = ["John", "Jane", "James", "Joe"]
var artistTitle = "John with Jane feat. James and Jill"
var filteredArtists = artists.filter(function(artist) {
return artistTitle.includes(artist);
});
console.log(filteredArtists);

The only issue I have with this is that the "artists" array will be around 2.5k items and Directus cannot load all of these in a Get Data operator and so filtering the array won't work. Perhaps there's a better way of handling this type of user input? It's worth mentioning that the user will most likely input the data through importing a csv file directly to a table in Directus.

pulsar spoke
#

@last tiger I don't think you can do this reliably in flows. But you can do so in hooks.

You have to create an filter / action hook, filter meaning blocking, and action meaning async or non-blocking.

These hook actions run just like flows, but you write custom code.

You will have to get the input, [onCreate], and then use the directus items-service inside the hook, [Read by Query] to get your results matching from the database. (Basically using the search feature of directus programmatically inside of your code).

Then you get those artists, and do whatever processing you want to do.

last tiger
pulsar spoke
#

No sorry. It is custom extensions.

last tiger
#

ah I see

pulsar spoke
#

Yes.

#

Take a look at this thread.

last tiger
#

I will keep this in mind, thank you. Currently, I don't have access to creating my own custom extensions (as I do not directly manage the instance) but I will seek to get access when I can as custom extensions might have to be the solution here

pulsar spoke
#

#1067994119596679229

pulsar spoke
#

Once, you have the general idea of the hook, working from dev, you can move it to the hosted directus.

last tiger
#

amazing, I'm going to look into attempting this locally now! Thank you so much for your help @pulsar spoke

pulsar spoke
#

@last tiger If you need help, let me know.