Make source ID generation function reusable to extensions (#11)

* Make source ID generation function reusable to extensions.

* Add parameters and return documentation.
This commit is contained in:
Alessandro Jean 2023-08-11 23:30:21 -03:00 committed by arkon
parent 64e9cbcfed
commit 542ff26701

View File

@ -32,9 +32,14 @@ abstract class HttpSource : CatalogueSource {
open val versionId: Int = throw Exception("Stub!") open val versionId: Int = throw Exception("Stub!")
/** /**
* Id of the source. By default it uses a generated id using the first 16 characters (64 bits) * ID of the source. By default it uses a generated id using the first 16 characters (64 bits)
* of the MD5 of the string: sourcename/language/versionId * of the MD5 of the string `"${name.lowercase()}/$lang/$versionId"`.
* Note the generated id sets the sign bit to 0. *
* The ID is generated by the [generateId] function, which can be reused if needed
* to generate outdated IDs for cases where the source name or language needs to
* be changed but migrations can be avoided.
*
* Note: the generated ID sets the sign bit to `0`.
*/ */
override val id: Long = throw Exception("Stub!") override val id: Long = throw Exception("Stub!")
@ -48,6 +53,26 @@ abstract class HttpSource : CatalogueSource {
*/ */
open val client: OkHttpClient = throw Exception("Stub!") open val client: OkHttpClient = throw Exception("Stub!")
/**
* Generates a unique ID for the source based on the provided [name], [lang] and
* [versionId]. It will use the first 16 characters (64 bits) of the MD5 of the string
* `"${name.lowercase()}/$lang/$versionId"`.
*
* Note: the generated ID sets the sign bit to `0`.
*
* Can be used to generate outdated IDs, such as when the source name or language
* needs to be changed but migrations can be avoided.
*
* @since extensions-lib 1.5
* @param name [String] the name of the source
* @param lang [String] the language of the source
* @param versionId [Int] the version ID of the source
* @return a unique ID for the source
*/
protected fun generateId(name: String, lang: String, versionId: Int): Long {
throw Exception("Stub!")
}
/** /**
* Headers builder for requests. Implementations can override this method for custom headers. * Headers builder for requests. Implementations can override this method for custom headers.
*/ */